:root {
  --bg: #0b1020;
  --bg-elev: #121a2f;
  --bg-elev-2: #18233d;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8eefc;
  --muted: #8b9bb8;
  --accent: #6ea8ff;
  --accent-2: #8b7cff;
  --correct: #3dcf8e;
  --correct-bg: rgba(61, 207, 142, 0.16);
  --wrong: #3a4663;
  --danger: #ff6b7a;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --slot: 72px;
  --max: 480px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(110, 168, 255, 0.14), transparent 55%),
    radial-gradient(800px 400px at 100% 20%, rgba(139, 124, 255, 0.1), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  line-height: 1.45;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

.app {
  width: min(100%, var(--max));
  margin: 0 auto;
  padding: 16px 16px 40px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.top {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
}

.brand {
  text-align: center;
}

.brand h1 {
  margin: 0;
  font-size: 1.28rem;
  letter-spacing: -0.03em;
  font-weight: 700;
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-style: italic;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: 1.05rem;
  font-weight: 700;
  transition: background 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--bg-elev-2);
  border-color: rgba(255, 255, 255, 0.14);
}

.meta-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

@media (max-width: 420px) {
  .meta-bar {
    grid-template-columns: repeat(2, 1fr);
  }
}

.diff-easy {
  color: var(--correct) !important;
}

.diff-medium {
  color: #f0b429 !important;
}

.diff-hard,
.diff-expert {
  color: var(--danger) !important;
}

.panel-sub {
  margin-left: 8px;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 700;
  vertical-align: middle;
}

/* Mini ladder strip under meta */
.ladder-peek {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}

.ladder-peek:hover {
  border-color: rgba(110, 168, 255, 0.35);
  background: var(--bg-elev-2);
}

.peek-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.peek-bar {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 12px rgba(110, 168, 255, 0.35);
  transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
  min-width: 12%;
  justify-self: center;
}

.peek-diff {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
}

.slot.locked {
  border-style: solid;
  border-color: color-mix(in srgb, var(--correct) 55%, transparent);
  background: var(--correct-bg);
  cursor: default;
}

.slot.locked::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.65rem;
  color: var(--correct);
  font-weight: 700;
}

.meta-item {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
}

.meta-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 2px;
}

.meta-value {
  font-family: var(--mono);
  font-size: 0.92rem;
  font-weight: 600;
}

.panel-title {
  margin: 0 0 10px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 600;
}

.clues-panel,
.board-panel,
.history-panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.clues {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  counter-reset: clue;
}

.clues li {
  counter-increment: clue;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: start;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-size: 0.98rem;
}

.clues li::before {
  content: counter(clue);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(110, 168, 255, 0.12);
  border: 1px solid rgba(110, 168, 255, 0.22);
}

.clue-text strong {
  font-weight: 600;
}

.item-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px 1px 4px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--chip, #888) 45%, transparent);
  background: color-mix(in srgb, var(--chip, #888) 16%, transparent);
  font-weight: 600;
  font-size: 0.92em;
  white-space: nowrap;
  vertical-align: baseline;
}

.item-chip .glyph {
  font-size: 1.05em;
  line-height: 1;
}

.hint-line {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

.slots {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.slot {
  aspect-ratio: 1;
  min-height: 56px;
  border-radius: 14px;
  border: 2px dashed rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: relative;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
  user-select: none;
  touch-action: none;
}

.slot .pos {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 0.65rem;
  font-family: var(--mono);
  color: var(--muted);
  opacity: 0.8;
}

.slot.filled {
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.12);
  background: var(--bg-elev-2);
}

.slot.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(110, 168, 255, 0.2);
}

.slot.drag-over {
  border-color: var(--accent-2);
  background: rgba(139, 124, 255, 0.12);
}

.slot .glyph {
  font-size: 1.55rem;
  line-height: 1;
}

.slot .name {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 2px;
}

.tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  min-height: 64px;
  margin-bottom: 14px;
}

.tray-item {
  width: var(--slot);
  min-height: 64px;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--chip, #888) 40%, transparent);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--chip, #888) 18%, transparent), transparent 70%),
    var(--bg-elev-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: grab;
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.12s;
  user-select: none;
  touch-action: none;
}

.tray-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

.tray-item.selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tray-item.placed {
  opacity: 0.28;
  pointer-events: none;
  filter: grayscale(0.4);
}

.tray-item .glyph {
  font-size: 1.6rem;
  line-height: 1;
}

.tray-item .name {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
}

.btn {
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b1020;
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
}

.btn.ghost:hover:not(:disabled) {
  background: var(--bg-elev-2);
}

.btn.wide {
  width: 100%;
}

.history {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.attempt-row {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  align-items: center;
}

.attempt-num {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.attempt-slots {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.mini-slot {
  aspect-ratio: 1;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  border: 1px solid transparent;
}

.mini-slot.correct {
  background: var(--correct-bg);
  border-color: color-mix(in srgb, var(--correct) 50%, transparent);
}

.mini-slot.wrong {
  background: rgba(58, 70, 99, 0.55);
  border-color: rgba(255, 255, 255, 0.06);
}

.foot {
  margin-top: auto;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding-top: 8px;
}

/* Modal */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: calc(100% - 32px);
  width: 400px;
  color: var(--text);
}

.modal::backdrop {
  background: rgba(4, 8, 18, 0.72);
  backdrop-filter: blur(4px);
}

.modal-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0 0 14px;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.help-list {
  margin: 0 0 14px;
  padding-left: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: #c9d4ea;
  font-size: 0.95rem;
}

.help-list ul {
  margin: 8px 0 0;
  padding-left: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  margin-right: 6px;
  vertical-align: -2px;
}

.swatch.correct {
  background: var(--correct);
}

.swatch.wrong {
  background: var(--wrong);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.help-tip {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-box {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}

.stat-box .n {
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 600;
}

.stat-box .l {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}

.result-sub {
  color: var(--muted);
  margin: 0 0 14px;
}

.share-preview {
  font-family: var(--mono);
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  line-height: 1.45;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
  white-space: pre-wrap;
  text-align: center;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #f2f6ff;
  color: #0b1020;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  z-index: 50;
  animation: toast-in 0.2s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.locked .tray-item,
.locked .slot {
  cursor: default;
}

.locked .tray-item:hover {
  transform: none;
  box-shadow: none;
}

/* —— Ladder modal visual —— */
.ladder-modal {
  width: min(420px, calc(100% - 24px));
}

.ladder-card {
  max-height: min(90dvh, 720px);
  overflow: auto;
}

.ladder-view {
  margin-bottom: 14px;
}

.ladder-stage {
  --ladder-width: 100%;
}

.ladder-frame {
  background:
    linear-gradient(180deg, rgba(110, 168, 255, 0.08), transparent 40%),
    var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 12px 12px;
}

.ladder-sky {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.ladder {
  position: relative;
  margin: 0 auto;
  min-height: 220px;
  transition: width 0.55s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.rail {
  position: absolute;
  top: 0;
  bottom: 28px;
  width: 6px;
  border-radius: 6px;
  background: linear-gradient(
    180deg,
    rgba(139, 124, 255, 0.35),
    rgba(110, 168, 255, 0.75)
  );
  box-shadow: 0 0 12px rgba(110, 168, 255, 0.2);
}

.rail.left {
  left: 0;
}

.rail.right {
  right: 0;
}

.rungs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0 0;
  position: relative;
  z-index: 1;
}

.rung {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 28px;
}

.rung-bar {
  width: var(--rung-w, 100%);
  height: 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.2s;
  margin: 0 auto;
}

.rung.cleared .rung-bar {
  background: var(--correct-bg);
  border-color: color-mix(in srgb, var(--correct) 45%, transparent);
}

.rung.current .rung-bar {
  background: rgba(110, 168, 255, 0.22);
  border-color: rgba(110, 168, 255, 0.55);
  box-shadow: 0 0 16px rgba(110, 168, 255, 0.25);
}

.rung.future .rung-bar {
  opacity: 0.45;
}

.rung-num {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text);
}

.rung-diff {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.climber {
  position: absolute;
  right: -2px;
  top: 50%;
  transform: translate(50%, -50%);
  font-size: 1.25rem;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45));
  z-index: 2;
}

.ladder-stage.anim .climber {
  animation: climb-bob 0.7s ease;
}

.climber.cheer {
  animation: climb-cheer 0.55s ease;
}

.climber.fallen {
  animation: fall-shake 0.45s ease;
}

@keyframes climb-bob {
  0% {
    transform: translate(50%, 40%);
    opacity: 0.2;
  }
  100% {
    transform: translate(50%, -50%);
    opacity: 1;
  }
}

@keyframes climb-cheer {
  0% {
    transform: translate(50%, 20%) scale(0.8);
  }
  60% {
    transform: translate(50%, -70%) scale(1.15);
  }
  100% {
    transform: translate(50%, -50%) scale(1);
  }
}

@keyframes fall-shake {
  0%,
  100% {
    transform: translate(50%, -50%);
  }
  25% {
    transform: translate(40%, -30%) rotate(-12deg);
  }
  75% {
    transform: translate(60%, -20%) rotate(10deg);
  }
}

.ground {
  text-align: center;
  margin-top: 6px;
  padding: 8px;
  border-radius: 10px;
  background: rgba(163, 132, 92, 0.2);
  border: 1px solid rgba(163, 132, 92, 0.35);
  font-size: 0.75rem;
  color: #c4a574;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.ladder-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.ladder-stat {
  text-align: center;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 8px 4px;
  border: 1px solid var(--border);
}

.ladder-stat .k {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 2px;
}

.ladder-stat .v {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.95rem;
}

.ladder-stat .v.mono {
  letter-spacing: 0.12em;
  color: var(--accent);
}

@media (max-width: 400px) {
  :root {
    --slot: 60px;
  }

  .slot .name,
  .tray-item .name {
    font-size: 0.58rem;
  }

  .slot .glyph,
  .tray-item .glyph {
    font-size: 1.35rem;
  }
}
