:root {
  color-scheme: dark;
  --bg: #110f0d;
  --panel: rgba(29, 22, 17, 0.9);
  --panel-strong: #241b15;
  --panel-soft: rgba(65, 48, 33, 0.72);
  --text: #f3e6c8;
  --muted: #c7b08a;
  --brass: #d4a85f;
  --copper: #b46e43;
  --ember: #ef7d44;
  --steam: #9cc8d5;
  --line: rgba(246, 214, 160, 0.14);
  --success: #78d39b;
  --danger: #ea7a74;
  --shadow: rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 0%, rgba(180, 193, 203, 0.16), transparent 28%),
    radial-gradient(circle at 18% 18%, rgba(235, 241, 246, 0.11), transparent 18%),
    radial-gradient(circle at 84% 16%, rgba(224, 229, 234, 0.08), transparent 20%),
    radial-gradient(circle at 50% 52%, rgba(104, 114, 123, 0.18), transparent 26%),
    linear-gradient(180deg, #14181d 0%, #0f1317 42%, #090c0f 100%);
}

.backdrop {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 15% 24%, rgba(222, 228, 234, 0.18), transparent 0 18%, rgba(222, 228, 234, 0.06) 18% 22%, transparent 22% 100%),
    radial-gradient(circle at 82% 20%, rgba(222, 228, 234, 0.15), transparent 0 16%, rgba(222, 228, 234, 0.05) 16% 20%, transparent 20% 100%),
    radial-gradient(circle at 50% 30%, rgba(222, 228, 234, 0.08), transparent 0 12%, rgba(222, 228, 234, 0.03) 12% 16%, transparent 16% 100%),
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    radial-gradient(circle at center, transparent 0 58%, rgba(0, 0, 0, 0.3) 100%);
  background-size: 100% 100%, 100% 100%, 100% 100%, 56px 56px, 56px 56px, cover;
  opacity: 0.52;
  filter: blur(0.3px);
}

.app-shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
  position: relative;
}

.hero {
  display: grid;
  gap: 8px;
  margin-bottom: 24px;
}

.eyebrow,
.section-label {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--steam);
  font-size: 0.72rem;
}

h1,
h2 {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.02em;
}

h1 {
  font-size: clamp(2.6rem, 4vw, 4.6rem);
  line-height: 0.95;
  color: #fff2d6;
  text-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

h2 {
  font-size: 1.45rem;
}

.subtitle {
  max-width: 68ch;
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.55;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.7fr) minmax(0, 1.3fr);
  gap: 20px;
  align-items: start;
}

.board-card,
.panel-card {
  border: 1px solid var(--line);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(47, 56, 64, 0.92), rgba(18, 22, 27, 0.97)),
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.04), transparent 45%);
  box-shadow:
    0 24px 80px var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.board-card {
  padding: 22px;
}

.board-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 18px;
}

.board-tools {
  display: flex;
  flex-direction: column;
  align-items: end;
  gap: 10px;
}

.board-tool-buttons {
  display: flex;
  gap: 8px;
}

.stats {
  display: flex;
  gap: 14px;
}

.stats div {
  min-width: 86px;
  padding: 12px 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(72, 53, 36, 0.9), rgba(36, 27, 21, 0.9));
  border: 1px solid rgba(255, 226, 167, 0.12);
  text-align: center;
}

.stats span {
  display: block;
  color: #ffe1a0;
  font-size: 1.65rem;
  line-height: 1;
  font-weight: 700;
}

.stats small {
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

.board-wrap {
  display: flex;
  justify-content: center;
  padding: 16px 0 22px;
  position: relative;
}

.board-wrap::before,
.board-wrap::after {
  content: "";
  position: absolute;
  width: 160px;
  height: 160px;
  pointer-events: none;
  opacity: 0.42;
  background: url("assets/gear-ornament.svg") center / contain no-repeat;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.35));
}

.board-wrap::before {
  left: 8px;
  top: -8px;
}

.board-wrap::after {
  right: 8px;
  bottom: -4px;
  transform: rotate(17deg);
}

.board-frame {
  width: min(100%, 680px);
  aspect-ratio: 1;
  position: relative;
  border-radius: 38px;
  container-type: inline-size;
  background:
    radial-gradient(circle at center, rgba(232, 239, 245, 0.08), transparent 42%),
    linear-gradient(145deg, rgba(72, 81, 90, 0.94), rgba(19, 24, 29, 0.99));
  border: 1px solid rgba(255, 226, 167, 0.18);
  box-shadow:
    inset 0 0 0 8px rgba(10, 8, 7, 0.6),
    inset 0 0 40px rgba(0, 0, 0, 0.25),
    0 20px 50px rgba(0, 0, 0, 0.45);
}

.board {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.board-links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 4;
  pointer-events: none;
}

.board-pipe-shell,
.board-pipe-core,
.board-pipe-highlight {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.board-pipe-shell {
  stroke: rgba(48, 56, 63, 0.96);
  stroke-width: 10;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.38));
}

.board-pipe-core {
  stroke: rgba(141, 153, 164, 0.96);
  stroke-width: 7;
  filter: drop-shadow(0 0 5px rgba(198, 211, 221, 0.2));
}

.board-pipe-highlight {
  stroke: rgba(228, 235, 241, 0.74);
  stroke-width: 2;
  stroke-dasharray: 18 26;
  filter: drop-shadow(0 0 2px rgba(245, 248, 250, 0.24));
}

.board-pipe-joint-shell {
  fill: rgba(41, 48, 54, 0.96);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

.board-pipe-joint-core {
  fill: rgba(160, 170, 179, 0.98);
  stroke: rgba(221, 229, 235, 0.62);
  stroke-width: 1.1;
}

.board-pipe-valve-lines {
  fill: none;
  stroke: rgba(37, 44, 50, 0.9);
  stroke-width: 1.8;
  stroke-linecap: round;
}

.board-pipe-valve-core {
  fill: rgba(205, 214, 221, 0.92);
  stroke: rgba(80, 88, 96, 0.56);
  stroke-width: 0.8;
}

.board-pipe-arrow {
  fill: rgba(220, 228, 234, 0.84);
  filter: drop-shadow(0 0 2px rgba(244, 247, 250, 0.28));
}

.board-pipe-live {
  animation: pipe-live-pulse 1s ease-in-out infinite;
}

.board-pipe-arrow-live {
  transform-box: fill-box;
  transform-origin: center;
  animation: pipe-arrow-pulse 900ms ease-in-out infinite;
}

@keyframes pipe-live-pulse {
  0%,
  100% {
    filter: drop-shadow(0 0 5px rgba(198, 211, 221, 0.22));
    opacity: 1;
  }

  50% {
    filter: drop-shadow(0 0 8px rgba(233, 240, 245, 0.45));
    opacity: 0.92;
  }
}

@keyframes pipe-arrow-pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.82;
  }

  50% {
    transform: scale(1.18);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .board-pipe-live,
  .board-pipe-arrow-live {
    animation: none;
  }
}

.side {
  position: absolute;
  display: flex;
  gap: 12px;
}

.side-top,
.side-bottom {
  left: 50%;
  transform: translateX(-50%);
}

.side-top {
  top: 32px;
}

.side-bottom {
  bottom: 32px;
}

.side-left,
.side-right {
  top: 50%;
  flex-direction: column;
  transform: translateY(-50%);
}

.side-left {
  left: 32px;
}

.side-right {
  right: 32px;
}

.side-left .tile,
.side-right .tile {
  display: flex;
  align-items: center;
}

.side-left .tile {
  flex-direction: row-reverse;
}

.side-right .tile {
  flex-direction: row;
}

.tile {
  position: relative;
  width: 102px;
  height: 84px;
}

.tile-letter {
  position: relative;
  width: 100%;
  height: 100%;
  border: 1px solid rgba(255, 232, 192, 0.32);
  border-radius: 20px;
  background: url("assets/tank-silver.svg") center / cover no-repeat;
  color: #1c1713;
  font-family: inherit;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  box-shadow:
    0 12px 20px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    inset 0 -1px 0 rgba(45, 26, 16, 0.5);
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease, box-shadow 140ms ease;
}

.tile-letter.used {
  background: url("assets/tank-patina.svg") center / cover no-repeat;
  color: #10211c;
  border-color: rgba(186, 235, 212, 0.32);
  box-shadow:
    0 10px 18px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.24),
    0 0 0 2px rgba(156, 200, 181, 0.2);
}

.tile-letter:hover,
.tile-letter:focus-visible,
button:hover,
button:focus-visible {
  outline: none;
  transform: translateY(-2px);
  filter: brightness(1.08);
}

.tile-x2:hover,
.tile-x2:focus-visible {
  outline: none;
  transform: translateY(-1px);
  filter: brightness(1.04);
}

.tile-letter:active,
.tile-x2:active,
button:active {
  transform: translateY(1px) scale(0.98);
}

.tile-x2 {
  position: absolute;
  right: -9px;
  bottom: -9px;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid rgba(255, 237, 204, 0.28);
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.18), transparent 24%),
    linear-gradient(180deg, #d9b067 0%, #9a5b32 100%);
  color: #2d160d;
  font-size: 0.7rem;
  font-weight: 700;
  opacity: 0.82;
  cursor: pointer;
  box-shadow:
    0 8px 12px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 6px;
}

#submitBtn {
  margin-left: auto;
}

button {
  border: 0;
  border-radius: 16px;
  font: inherit;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.primary,
.secondary {
  padding: 14px 18px;
  color: var(--text);
  box-shadow: 0 12px 22px rgba(0, 0, 0, 0.24);
}

.primary {
  background: linear-gradient(180deg, #e6b463 0%, #a45e2c 100%);
  color: #2a160c;
  font-weight: 700;
}

.secondary {
  background: linear-gradient(180deg, #413126 0%, #2c2119 100%);
  border: 1px solid rgba(255, 226, 167, 0.12);
}

.help-btn {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.84rem;
  color: var(--steam);
  background: linear-gradient(180deg, rgba(53, 40, 30, 0.95), rgba(28, 21, 16, 0.96));
  border: 1px solid rgba(156, 200, 213, 0.3);
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.24);
}

.panel {
  display: grid;
  gap: 18px;
}

.panel-card {
  padding: 18px;
}

.current-word {
  min-height: 78px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 14px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(19, 15, 12, 0.88), rgba(36, 27, 21, 0.72));
  border: 1px solid rgba(255, 226, 167, 0.12);
  margin: 12px 0 10px;
}

.current-word.empty {
  color: rgba(243, 230, 200, 0.55);
}

.token {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(227, 232, 236, 0.98), rgba(138, 149, 159, 0.96));
  color: #1d2329;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.token.x2::after {
  content: "x2";
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(241, 246, 250, 0.98), rgba(167, 177, 186, 0.98));
  color: #1d2329;
  font-size: 0.68rem;
  font-weight: 700;
}

.message {
  min-height: 1.4em;
  color: var(--muted);
}

.message.success {
  color: var(--success);
}

.message.error {
  color: var(--danger);
}

.helper-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.legend {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend-swatch {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 226, 167, 0.26);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.legend-swatch.brass {
  background: linear-gradient(180deg, #c78c52 0%, #8a4f2e 100%);
}

.legend-swatch.patina {
  background: linear-gradient(180deg, #7ea694 0%, #4e6e62 100%);
  border-color: rgba(186, 235, 212, 0.45);
}

.found-words {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.word-pill {
  border-radius: 999px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(227, 232, 236, 0.96), rgba(138, 149, 159, 0.94));
  border: 1px solid rgba(222, 230, 236, 0.3);
  color: #1d2329;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.34);
}

.word-pill small {
  color: #2b3f50;
  margin-left: 8px;
}

.help-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(6, 5, 4, 0.64);
  z-index: 20;
}

.help-modal[hidden] {
  display: none !important;
}

.help-dialog {
  width: min(560px, 100%);
  border-radius: 20px;
  border: 1px solid rgba(255, 226, 167, 0.18);
  background: linear-gradient(180deg, rgba(43, 33, 25, 0.98), rgba(19, 15, 12, 0.98));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  padding: 18px;
}

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

.help-close {
  padding: 8px 12px;
  border-radius: 10px;
  background: linear-gradient(180deg, #413126 0%, #2c2119 100%);
  border: 1px solid rgba(255, 226, 167, 0.12);
  color: var(--text);
}

.help-copy {
  margin: 0 0 10px;
  color: var(--muted);
}

.help-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
  color: var(--text);
}

.help-actions {
  margin-top: 14px;
  display: flex;
  justify-content: end;
}

.board-input-grid {
  margin-top: 8px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 10px;
  align-items: center;
}

.board-input-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.board-input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(255, 226, 167, 0.2);
  background: linear-gradient(180deg, rgba(28, 21, 16, 0.95), rgba(19, 15, 12, 0.95));
  color: var(--text);
  padding: 9px 10px;
  font: inherit;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.board-paste {
  margin-top: 6px;
  resize: vertical;
  min-height: 86px;
  text-transform: none;
  letter-spacing: 0;
}

.board-paste-actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.board-input:focus-visible {
  outline: 1px solid rgba(156, 200, 213, 0.6);
  outline-offset: 1px;
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 820px) {
  .app-shell {
    width: min(100vw - 20px, 1280px);
    padding-top: 16px;
  }

  .board-card,
  .panel-card {
    border-radius: 22px;
  }

  .board-frame {
    width: 100%;
  }

  .tile {
    width: 86px;
    height: 72px;
  }

  .tile-letter {
    font-size: 1.6rem;
  }

  .tile-x2 {
    right: -8px;
    bottom: -8px;
    width: 32px;
    height: 32px;
  }

  .side-top,
  .side-bottom {
    gap: 8px;
  }

  .side-left,
  .side-right {
    gap: 8px;
  }

  .side-top {
    top: 28px;
  }

  .side-bottom {
    bottom: 28px;
  }

  .side-left {
    left: 24px;
  }

  .side-right {
    right: 24px;
  }

  .panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 500px) {
  .app-shell {
    width: calc(100vw - 16px);
  }

  .board-card {
    padding: 12px;
  }

  .board-wrap::before,
  .board-wrap::after {
    display: none;
  }
}

/* Scale tiles relative to the board frame width so corners never collide.
   17cqw × 3 tiles + 2cqw × 2 gaps = 55cqw row width, centred starts at 22.5cqw.
   Left column ends at 2.5cqw + 17cqw = 19.5cqw — no overlap. */
@container (max-width: 500px) {
  .tile {
    width: 17cqw;
    height: 14cqw;
  }

  .tile-letter {
    font-size: 6cqw;
    border-radius: 3.5cqw;
  }

  .tile-x2 {
    width: 6cqw;
    height: 6cqw;
    font-size: 2cqw;
    right: -2cqw;
    bottom: -2cqw;
  }

  .side-top {
    top: 2.5cqw;
    gap: 2cqw;
  }

  .side-bottom {
    bottom: 2.5cqw;
    gap: 2cqw;
  }

  .side-left {
    left: 2.5cqw;
    gap: 1.5cqw;
  }

  .side-right {
    right: 2.5cqw;
    gap: 1.5cqw;
  }
}