:root {
  /* Cold dungeon stone + tarnished iron + aged bronze + blood red */
  --bg: #0b0c0e;
  --bg-vignette:
    radial-gradient(140% 90% at 50% -10%, #1c2026 0%, #101216 38%, #0b0c0e 72%),
    radial-gradient(80% 60% at 15% 110%, rgba(150, 90, 40, 0.1) 0%, transparent 60%);

  --stone: #15171c;
  --stone-raised: #1c1f26;
  --stone-sunken: #101217;

  --iron: #2a2f39;
  --iron-light: #3b424f;
  --iron-dark: #0c0e12;

  --bronze: #c79a4b;
  --bronze-bright: #e6bd6b;
  --bronze-deep: #8a6a2f;
  --bronze-glow: rgba(230, 189, 107, 0.35);

  --parchment: #d9cfb8;
  --parchment-dim: #9c937e;
  --parchment-faint: #6a6457;

  --patina: #6fa07e;
  --patina-bg: rgba(95, 140, 110, 0.14);
  --patina-line: rgba(111, 160, 126, 0.5);

  --blood: #c0463c;
  --blood-bright: #d65b50;
  --blood-bg: rgba(160, 45, 38, 0.16);
  --blood-line: rgba(192, 70, 60, 0.5);

  --amber: #d9913f;
  --amber-bg: rgba(217, 145, 63, 0.14);
  --amber-line: rgba(217, 145, 63, 0.5);

  --radius: 6px;
  --radius-sm: 5px;

  --bevel: inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 -1px 0 rgba(0, 0, 0, 0.5);
  --display: "Cinzel", "Trajan Pro", Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg-vignette);
  background-color: var(--bg);
  background-attachment: fixed;
  color: var(--parchment);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

button {
  touch-action: manipulation;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: clamp(14px, 4vw, 26px) clamp(12px, 3.5vw, 20px)
    calc(40px + env(safe-area-inset-bottom));
  display: grid;
  gap: clamp(12px, 3vw, 18px);
}

@media (min-width: 900px) {
  .app {
    grid-template-columns: 1fr minmax(300px, 380px);
    grid-template-rows: auto 1fr auto;
    align-items: start;
  }

  .app-head {
    grid-column: 1 / -1;
  }

  .app-input {
    grid-column: 1;
    display: grid;
    gap: clamp(12px, 3vw, 18px);
  }

  .panel--sequence {
    grid-column: 2;
    grid-row: 2;
    position: sticky;
    top: clamp(12px, 3vw, 20px);
  }

  .app-foot {
    grid-column: 1 / -1;
  }

  .tumblers {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* --- header --- */

.app-head {
  text-align: center;
  padding: 8px 0 18px;
  border-bottom: 1px solid var(--iron);
  position: relative;
}

.app-head::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -1px;
  width: 120px;
  height: 1px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, var(--bronze), transparent);
}

.app-head h1 {
  margin: 0 0 10px;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.4rem, 6.5vw, 1.95rem);
  letter-spacing: clamp(1.5px, 0.8vw, 3px);
  text-transform: uppercase;
  color: var(--bronze-bright);
  text-shadow: 0 1px 0 #000, 0 0 22px var(--bronze-glow);
}

.tagline {
  margin: 0 auto;
  max-width: 44ch;
  color: var(--parchment-dim);
  font-size: 0.94rem;
}

.app-version-wrap {
  margin: 12px 0 0;
}

.app-version {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--iron-light);
  background: var(--stone-sunken);
  color: var(--parchment-dim);
  text-decoration: none;
  font-family: var(--display);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  transition: border-color 0.12s, color 0.12s;
}

.app-version:hover {
  border-color: var(--bronze-deep);
  color: var(--bronze);
}

/* --- panels (carved stone slabs) --- */

.panel {
  background: linear-gradient(180deg, var(--stone-raised), var(--stone));
  border: 1px solid var(--iron);
  border-top-color: var(--iron-light);
  border-radius: var(--radius);
  padding: clamp(13px, 3.5vw, 18px);
  box-shadow: var(--bevel), 0 10px 24px rgba(0, 0, 0, 0.45);
}

.panel h2 {
  margin: 0 0 12px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--bronze);
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--iron-light), transparent);
}

.sequence-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.sequence-head h2 {
  margin-bottom: 0;
}

.sequence-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.panel-note {
  margin: 0 0 16px;
  color: var(--parchment-dim);
  font-size: 0.9rem;
}

/* --- controls --- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.field-label {
  font-family: var(--display);
  letter-spacing: 1px;
  text-transform: uppercase;
  font-size: 0.82rem;
  color: var(--parchment-dim);
  margin-right: 2px;
}

.pill-row {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  min-width: 46px;
  min-height: 46px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--iron-light);
  background: linear-gradient(180deg, var(--iron), var(--iron-dark));
  color: var(--parchment);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--bevel);
  transition: border-color 0.12s, color 0.12s, box-shadow 0.12s;
}

.pill:active {
  transform: translateY(1px);
}

.pill.is-active {
  background: linear-gradient(180deg, var(--bronze-bright), var(--bronze-deep));
  border-color: var(--bronze-bright);
  color: #1a1206;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 14px var(--bronze-glow), var(--bevel);
}

.pill.is-copied {
  border-color: var(--patina);
  color: var(--patina);
}

.pill-ghost {
  font-weight: 500;
  color: var(--parchment-dim);
  background: linear-gradient(180deg, var(--stone-raised), var(--stone-sunken));
  border-color: var(--iron);
}

.pill[disabled] {
  opacity: 0.4;
  cursor: default;
}

/* --- tumblers (in-game plate cards) --- */

.tumblers {
  display: grid;
  gap: clamp(10px, 2.5vw, 14px);
}

.hole-legend {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px 4px;
  font-size: 0.72rem;
  letter-spacing: 0.5px;
  color: var(--parchment-dim);
  text-transform: uppercase;
  grid-column: 1 / -1;
}

.hole-legend-wall {
  color: var(--blood-bright);
  font-weight: 700;
}

.hole-legend-notch {
  color: var(--bronze);
  font-weight: 700;
}

.tumbler-card {
  background: linear-gradient(180deg, #1a1d24 0%, #12141a 100%);
  border: 1px solid var(--iron);
  border-radius: var(--radius);
  padding: clamp(12px, 3vw, 16px);
  box-shadow: var(--bevel), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  border-left: 3px solid transparent;
}

.tumbler-card.at-edge {
  border-left-color: var(--blood);
}

.tumbler-card.at-edge .tumbler-title {
  color: var(--blood-bright);
}

.tumbler-card.near-edge {
  border-left-color: var(--amber);
}

.tumbler-card.near-edge .tumbler-title {
  color: var(--amber);
}

.tumbler-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.tumbler-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(0.9rem, 3.2vw, 1rem);
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--bronze);
}

.tumbler-sub {
  font-size: 0.72rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--parchment-faint);
}

.tumbler-start,
.tumbler-links {
  display: grid;
  gap: 8px;
}

.tumbler-links {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--iron);
}

.tumbler-field-label {
  font-family: var(--display);
  font-size: 0.72rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--parchment-dim);
}

.plate-holes {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: clamp(4px, 1.2vw, 6px);
  padding: 8px 6px;
  background: var(--stone-sunken);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.6),
    inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.hole {
  aspect-ratio: 1;
  min-height: 40px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 55%, #08090c 0%, #151820 70%);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.85),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  color: var(--parchment-faint);
  font-weight: 700;
  font-size: clamp(0.72rem, 2.8vw, 0.85rem);
  cursor: pointer;
  transition: box-shadow 0.12s, color 0.12s, transform 0.1s;
}

.hole.is-notch {
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.85),
    inset 0 0 0 1px var(--bronze-deep);
  color: var(--bronze);
}

.hole.is-wall:not(.is-active) {
  color: var(--blood-bright);
}

.hole.is-active {
  background: radial-gradient(circle at 42% 32%, var(--bronze-bright), var(--bronze-deep));
  box-shadow: 0 0 10px var(--bronze-glow),
    inset 0 -2px 4px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  color: #160f04;
  transform: translateY(-1px);
}

.hole:not(.is-active):active {
  transform: scale(0.96);
}

.link-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.link-chip {
  min-height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--iron);
  background: var(--stone-sunken);
  color: var(--parchment-dim);
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.link-chip:active {
  transform: translateY(1px);
}

.link-chip.link-none {
  color: var(--parchment-faint);
}

.link-chip.link-same {
  color: var(--patina);
  background: var(--patina-bg);
  border-color: var(--patina-line);
}

.link-chip.link-opp {
  color: var(--blood-bright);
  background: var(--blood-bg);
  border-color: var(--blood-line);
}

/* --- solution --- */

.solve-btn {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--bronze-bright);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, var(--bronze-bright), var(--bronze-deep));
  color: #160f04;
  font-family: var(--display);
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  cursor: pointer;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 20px var(--bronze-glow), var(--bevel);
}

.solve-btn:active {
  transform: translateY(1px);
}

.solution {
  margin-top: 16px;
}

.sequence-min {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.sequence-min-step {
  font-family: var(--display);
  font-size: 0.82rem;
  color: var(--parchment-dim);
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.sequence-min-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.sequence-min-done {
  font-family: var(--display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--patina);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--iron-light);
  background: linear-gradient(180deg, var(--stone-raised), var(--stone-sunken));
  color: var(--bronze-bright);
  cursor: pointer;
  box-shadow: var(--bevel);
  transition: border-color 0.12s, box-shadow 0.12s;
}

.icon-btn:hover:not(:disabled) {
  border-color: var(--bronze-deep);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--bronze);
  outline-offset: 2px;
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.icon-btn svg {
  display: block;
  width: 1.1rem;
  height: 1.1rem;
  fill: currentColor;
}

.icon-btn svg[fill="none"] {
  fill: none;
  stroke: currentColor;
}

.icon-btn--tool {
  width: 2.25rem;
  height: 2.25rem;
}

.icon-btn--tool svg {
  width: 1rem;
  height: 1rem;
}

@media (max-width: 899px) {
  .panel--sequence {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin-bottom: -8px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    box-shadow: var(--bevel), 0 -8px 24px rgba(0, 0, 0, 0.5);
  }

  .panel--sequence:not(.is-minimized) .solution {
    max-height: min(58vh, calc(100dvh - 12rem));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .panel--sequence.has-solution .solve-btn {
    display: none;
  }
}

.hint {
  color: var(--parchment-dim);
  font-style: italic;
}

.success {
  font-family: var(--display);
  letter-spacing: 1px;
  color: var(--patina);
  font-weight: 700;
}

.solution-count {
  margin: 0 0 14px;
  font-size: 1.35rem;
  letter-spacing: 2px;
  text-align: center;
  text-transform: uppercase;
}

.alert {
  font-family: var(--display);
  letter-spacing: 0.5px;
  color: var(--blood-bright);
  font-weight: 700;
}

.step-toggle {
  margin-top: 12px;
  width: 100%;
}

.step-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 7px;
}

.step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, var(--stone-raised), var(--stone-sunken));
  border: 1px solid var(--iron);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.12s, box-shadow 0.12s, opacity 0.12s;
}

.step:hover {
  border-color: var(--bronze-deep);
}

.step:focus-visible {
  outline: 2px solid var(--bronze);
  outline-offset: 2px;
}

.step.is-current {
  border-color: var(--bronze);
  box-shadow: 0 0 14px var(--bronze-glow);
}

.step.is-done {
  opacity: 0.55;
}

.step.is-done .step-text {
  text-decoration: line-through;
  color: var(--parchment-dim);
}

.step.is-upcoming {
  opacity: 0.82;
}

.step-num {
  flex: 0 0 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, var(--bronze-bright), var(--bronze-deep));
  border: 1px solid var(--bronze-bright);
  color: #160f04;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.step.is-done .step-num {
  background: radial-gradient(circle at 50% 38%, var(--patina), #3f6b50);
  border-color: var(--patina);
  color: #0c160f;
}

.step.is-upcoming .step-num {
  background: linear-gradient(180deg, var(--iron), var(--iron-dark));
  border-color: var(--iron-light);
  color: var(--parchment-dim);
  box-shadow: none;
}

.step-text {
  font-weight: 600;
}

/* --- walkthrough --- */

.walkthrough {
  margin-top: 16px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--stone-sunken);
  border: 1px solid var(--iron);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
}

.wt-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
}

.wt-nav .pill {
  flex: 1;
}

.wt-progress {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.wt-counter {
  font-family: var(--display);
  letter-spacing: 1px;
  color: var(--parchment-dim);
  font-weight: 700;
  font-size: 0.85rem;
}

.wt-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--stone-raised);
  border: 1px solid var(--iron);
  overflow: hidden;
}

.wt-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--bronze-deep), var(--bronze-bright));
  transition: width 0.18s ease;
}

.pill-primary {
  background: linear-gradient(180deg, var(--bronze-bright), var(--bronze-deep));
  border-color: var(--bronze-bright);
  color: #1a1206;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 14px var(--bronze-glow), var(--bevel);
}

.wt-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(52px, 1fr));
  gap: 8px;
  padding: 4px 0;
}

.wt-plate {
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--iron);
  background: linear-gradient(180deg, var(--iron), var(--iron-dark));
  box-shadow: var(--bevel);
}

.wt-plate.is-moving {
  border-color: var(--bronze-bright);
  box-shadow: 0 0 14px var(--bronze-glow);
}

.wt-plate.at-edge {
  border-color: var(--blood);
  box-shadow: 0 0 12px var(--blood-bg);
}

.wt-plate.near-edge {
  border-color: var(--amber-line);
  box-shadow: 0 0 10px var(--amber-bg);
}

.wt-label {
  font-family: var(--display);
  color: var(--parchment-faint);
  font-size: 0.74rem;
  font-weight: 700;
}

.wt-value {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--stone-sunken);
  border: 1px solid var(--iron-light);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--parchment);
}

.wt-value.is-center {
  background: radial-gradient(circle at 50% 38%, var(--bronze-bright), var(--bronze-deep));
  border-color: var(--bronze-bright);
  color: #160f04;
  box-shadow: 0 0 12px var(--bronze-glow), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.wt-current {
  margin: 14px 0;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 4rem;
}

.wt-current.is-open {
  font-family: var(--display);
  letter-spacing: 0.5px;
  color: var(--patina);
  font-weight: 700;
  font-size: 1.5rem;
  line-height: 1.2;
  text-align: center;
}

.move-cmd {
  display: inline-flex;
  align-items: center;
  gap: 0.75em;
}

.move-lock {
  font-family: var(--display);
  font-weight: 700;
  color: var(--bronze-bright);
}

.move-arrow {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, var(--bronze-bright), var(--bronze-deep));
  border: 1px solid var(--bronze-bright);
  box-shadow: 0 0 18px var(--bronze-glow), 0 0 4px var(--bronze-bright),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  color: #160f04;
}

.move-arrow svg {
  display: block;
  fill: currentColor;
}

.move-cmd--focus .move-arrow--right svg {
  transform: translateX(2px);
}

.move-cmd--focus .move-arrow--left svg {
  transform: translateX(-2px);
}

.move-cmd--list .move-arrow--right svg {
  transform: translateX(1px);
}

.move-cmd--list .move-arrow--left svg {
  transform: translateX(-1px);
}

.move-cmd--min .move-arrow--right svg {
  transform: translateX(1px);
}

.move-cmd--min .move-arrow--left svg {
  transform: translateX(-1px);
}

.move-cmd--focus .move-lock {
  font-size: 1.75rem;
}

.move-cmd--focus .move-arrow {
  width: 3.5rem;
  height: 3.5rem;
}

.move-cmd--focus .move-arrow svg {
  width: 2.5rem;
  height: 2.5rem;
}

.move-cmd--list .move-lock {
  font-size: 1rem;
}

.move-cmd--list .move-arrow {
  width: 2rem;
  height: 2rem;
}

.move-cmd--list .move-arrow svg {
  width: 1.5rem;
  height: 1.5rem;
}

.move-cmd--min .move-lock {
  font-size: 1.1rem;
}

.move-cmd--min .move-arrow {
  width: 2.5rem;
  height: 2.5rem;
}

.move-cmd--min .move-arrow svg {
  width: 1.85rem;
  height: 1.85rem;
}

.step.is-current .move-arrow {
  box-shadow: 0 0 18px var(--bronze-glow), 0 0 4px var(--bronze-bright),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* --- footer --- */

.app-foot {
  padding-top: 16px;
  border-top: 1px solid var(--iron);
  color: var(--parchment-faint);
  font-size: 0.82rem;
  text-align: center;
}

.app-foot-note {
  margin: 0 0 8px;
}

.app-foot-meta {
  margin: 0;
}

.app-foot-meta .app-version {
  font-size: 0.72rem;
  padding: 2px 10px;
}
