:root {
  --bg-0: #f6f2ee;
  --bg-1: #efe7e0;
  --surface-0: #fffaf7;
  --surface-1: #f8f1eb;
  --text-main: #2d2520;
  --text-soft: #6f6057;
  --text-faint: #9a887d;
  --accent: #bf8174;
  --accent-strong: #ab695d;
  --line: #ddc8be;

  --btn-text: #fffaf7;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at 12% 20%, rgba(255, 255, 255, 0.45), transparent 40%),
    radial-gradient(circle at 88% 80%, rgba(255, 255, 255, 0.3), transparent 36%),
    linear-gradient(155deg, var(--bg-0), var(--bg-1));
  display: grid;
  place-items: center;
  padding: 14px;
}

body.embedded {
  min-height: auto;
  display: block;
  padding: 0;
  background: transparent;
}

body.embedded .page {
  width: 100%;
}

body.embedded .game-shell {
  box-shadow: none;
}

.page {
  width: min(1040px, 100%);
}

.game-shell {
  position: relative;
  border: 3px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 14px 30px rgba(45, 37, 32, 0.16);
  overflow: hidden;
  background: var(--surface-0);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: manipulation;
}

.jump-btn {
  position: absolute;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  border: 1px solid var(--accent-strong);
  background: linear-gradient(180deg, #cb9387, var(--accent));
  color: var(--btn-text);
  border-radius: 999px;
  min-width: 186px;
  min-height: 58px;
  padding: 10px 22px;
  font-size: 19px;
  letter-spacing: 0.6px;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(45, 37, 32, 0.22);
  z-index: 4;
}

.jump-btn:active {
  transform: translateX(-50%) translateY(1px) scale(0.99);
}

.modal {
  position: absolute;
  inset: 0;
  background: rgba(45, 37, 32, 0.38);
  display: grid;
  place-items: center;
  padding: 12px;
  z-index: 7;
}

.hidden {
  display: none;
}

.modal-card {
  width: min(430px, 100%);
  max-height: min(92vh, 560px);
  overflow: hidden;
  background: var(--surface-0);
  border: 2px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 16px 32px rgba(45, 37, 32, 0.2);
  padding: 14px;
  text-align: left;
  font-family: "Courier New", monospace;
}

.modal-card h2,
.modal-card h3 {
  margin: 0;
  color: var(--text-main);
}

#gameOverTitle {
  font-size: 25px;
  line-height: 1;
  margin-bottom: 6px;
  letter-spacing: 0.1px;
  text-align: center;
}

.modal-line {
  margin: 0 0 4px;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.2;
}

#resultText {
  margin-top: 6px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  text-align: center;
}

.problem {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-strong);
  line-height: 1.2;
  text-align: center;
}

.fail-line {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-soft);
  line-height: 1.2;
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#nickname {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  font-weight: 400;
  margin-bottom: 2px;
  background: var(--surface-1);
  color: var(--text-main);
  outline: none;
}

#nickname::placeholder {
  color: var(--text-faint);
}

#nickname:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(191, 129, 116, 0.18);
}

.error {
  min-height: 0.6em;
  margin: 1px 0 2px;
  color: #b43f2f;
  font-size: 12px;
  font-weight: 400;
}

.modal-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: -2px;
  margin-bottom: 14px;
}

.modal-actions button {
  border: 1px solid var(--accent-strong);
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
  background: var(--accent);
  color: var(--btn-text);
  font-weight: 700;
  font-size: 13px;
  line-height: 1.1;
  min-height: 38px;
}

.modal-actions button:hover {
  background: var(--accent-strong);
}

.modal-actions button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.leaders {
  border-top: 1px dashed var(--line);
  padding-top: 8px;
}

.leaders h3 {
  font-size: 20px;
  margin: 0 0 8px;
  text-align: center;
  letter-spacing: 0.4px;
}

#leadersList {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.leader-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: linear-gradient(180deg, var(--surface-0), var(--surface-1));
}

.leader-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.leader-rank {
  width: 24px;
  height: 24px;
  border: 1px solid var(--accent-strong);
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--surface-0);
  background: var(--accent);
}

.leader-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.leader-score {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-strong);
}

.leader-empty {
  text-align: center;
  font-size: 15px;
  color: var(--text-soft);
  border: 1px dashed var(--line);
  border-radius: 9px;
  padding: 10px 8px;
  background: var(--surface-1);
}

@media (max-height: 760px) {
  .modal-card {
    padding: 12px;
  }

  #gameOverTitle {
    font-size: 23px;
  }

  .modal-line {
    font-size: 13px;
  }

  #resultText {
    font-size: 14px;
  }

  .problem {
    font-size: 16px;
  }

  .fail-line {
    font-size: 12px;
  }

  #nickname {
    font-size: 13px;
  }

  .modal-actions button {
    padding: 8px 10px;
    font-size: 12px;
  }

  .leader-name {
    max-width: 138px;
    font-size: 14px;
  }

  .leader-score {
    font-size: 13px;
  }
}

@media (min-width: 881px) {
  .jump-btn {
    display: none;
  }
}
