:root {
  --bg: #10131a;
  --panel: #1a1f2a;
  --panel-2: #212838;
  --text: #f5f7fb;
  --muted: #aab3c4;
  --line: #343d50;
  --accent: #7de2d1;
  --accent-strong: #4ec5b1;
  --warning: #ffca68;
  --danger: #ff7a85;
  --cell: #202737;
  --cell-hover: #2a3448;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(125, 226, 209, 0.09), transparent 34rem),
    radial-gradient(circle at 90% 20%, rgba(107, 123, 255, 0.08), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button { font: inherit; }

.shell {
  width: min(1440px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 20px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--accent);
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 4px;
  font-size: clamp(2.2rem, 5vw, 4.2rem);
  line-height: 0.95;
  letter-spacing: -0.05em;
}

.tagline { margin-bottom: 0; color: var(--muted); }

.game-layout {
  display: grid;
  grid-template-columns: minmax(230px, 0.75fr) minmax(420px, 1.55fr) minmax(230px, 0.75fr);
  gap: 18px;
  align-items: start;
}

.panel, .board-panel {
  background: rgba(26, 31, 42, 0.9);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.panel { padding: 18px; }
.board-panel { padding: 18px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
}

.stat-card {
  padding: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.stat-card strong {
  display: block;
  margin-top: 2px;
  font-size: 1.8rem;
}

.stat-label, .tiny-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}


.turn-timer {
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #121721;
  transition: border-color 140ms ease, background 140ms ease;
}

.turn-timer-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.turn-timer-head strong {
  color: var(--text);
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.timer-track {
  height: 9px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #090c12;
}

.timer-track > span {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  transform-origin: left center;
  transition: width 80ms linear, background 140ms ease;
}

.timer-hint {
  margin-top: 7px;
  min-height: 1.1em;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.3;
}

.turn-timer.running {
  border-color: rgba(125, 226, 209, 0.45);
}

.turn-timer.urgent {
  border-color: rgba(255, 122, 133, 0.72);
  background: rgba(255, 122, 133, 0.07);
}

.turn-timer.urgent .timer-track > span {
  background: linear-gradient(90deg, #ffca68, #ff7a85);
}

.turn-timer.urgent .turn-timer-head strong {
  color: #ffd4d8;
}

.panel-section { margin-top: 18px; }

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 0.88rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.level-meters { display: grid; gap: 8px; }
.level-meter-row {
  display: grid;
  grid-template-columns: 52px 1fr 42px;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}

.level-meter {
  height: 9px;
  overflow: hidden;
  background: #11151d;
  border: 1px solid var(--line);
  border-radius: 99px;
}

.level-meter > span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  transition: width 160ms ease;
}

.piece-card {
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.piece-name {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
}

.piece-preview {
  min-height: 122px;
  display: grid;
  place-items: center;
}

.preview-grid {
  display: grid;
  gap: 5px;
}

.preview-cell {
  width: 24px;
  aspect-ratio: 1;
  border-radius: 6px;
  background: var(--accent);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.2);
  display: grid;
  place-items: center;
  color: #081411;
  font-size: 0.78rem;
  font-weight: 900;
}

.preview-cell.piece-normal { background: var(--accent); }
.preview-cell.piece-wildcard {
  background: linear-gradient(180deg, #ffd769, #ffb936);
  color: #3a2200;
}
.preview-cell.piece-excavator {
  background: linear-gradient(180deg, #ff8d8d, #d75e5e);
  color: #2f0404;
}

.piece-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.button {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 14px;
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.button:hover { border-color: #53617a; transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.button-small { padding: 9px 8px; font-size: 0.78rem; }
.button-primary { background: var(--accent); color: #0a1715; border-color: transparent; font-weight: 900; }
.button-primary:hover { background: #94ebde; border-color: transparent; }
.button-ghost { background: transparent; }

.upcoming-pieces {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.upcoming-piece {
  min-height: 82px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

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

.upcoming-name {
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
}

.upcoming-preview {
  flex: 1;
  min-height: 46px;
  display: grid;
  place-items: center;
}

.upcoming-preview .preview-grid {
  gap: 3px;
}

.upcoming-preview .preview-cell {
  border-radius: 4px;
}

.placement-status {
  margin-top: 16px;
  padding: 12px;
  min-height: 64px;
  border-radius: 12px;
  background: #121721;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.placement-status strong { color: var(--text); }
.placement-status.danger { color: #ffd3d7; border-color: rgba(255,122,133,0.55); background: rgba(255,122,133,0.09); }
.placement-status.good { border-color: rgba(125,226,209,0.45); background: rgba(125,226,209,0.07); }

.board-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-width: 720px;
  margin: 0 auto;
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: clamp(5px, 1vw, 9px);
  padding: clamp(8px, 1.6vw, 14px);
  border-radius: 18px;
  background: #0b0e14;
  border: 1px solid #2d3546;
  touch-action: manipulation;
}

.board-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  border: 1px solid #354056;
  border-radius: clamp(8px, 1.5vw, 13px);
  background: var(--cell);
  color: #eef3ff;
  cursor: pointer;
  user-select: none;
  overflow: hidden;
  transition: background 100ms ease, transform 100ms ease, box-shadow 100ms ease;
}

.board-cell:hover { background: var(--cell-hover); }
.cell-height {
  position: relative;
  z-index: 2;
  font-size: clamp(1rem, 4vw, 2rem);
  font-weight: 900;
  line-height: 1;
}

.cell-bars {
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: 10%;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4%;
}

.cell-bars i, .demo-bars i {
  height: 4px;
  border-radius: 99px;
  background: rgba(255,255,255,0.14);
}

.cell-bars i.on, .demo-bars i.on { background: rgba(255,255,255,0.85); }

/* Stronger per-layer contrast so the stack reads more clearly at a glance. */
.level-1 {
  background: linear-gradient(180deg, #1ea672, #14825a);
  border-color: #49d29b;
}

.level-2 {
  background: linear-gradient(180deg, #2f8cff, #1c66cc);
  border-color: #78b8ff;
}

.level-3 {
  background: linear-gradient(180deg, #8a5cff, #6640c9);
  border-color: #b49bff;
}

.level-4 {
  background: linear-gradient(180deg, #d857b2, #a93586);
  border-color: #f39ad7;
}

.level-5 {
  background: linear-gradient(180deg, #e56b2e, #b94a16);
  border-color: #ffb083;
}

.board-cell.preview-safe,
.board-cell.preview-danger,
.board-cell.preview-out {
  isolation: isolate;
  transform: translateY(-2px) scale(1.025);
}

.board-cell.preview-safe::after,
.board-cell.preview-danger::after,
.board-cell.preview-out::after {
  content: "";
  position: absolute;
  inset: 4px;
  z-index: 1;
  border-radius: max(5px, calc(clamp(8px, 1.5vw, 13px) - 3px));
  pointer-events: none;
}

.board-cell.preview-safe {
  border-color: #ffffff;
  box-shadow: 0 0 0 3px #ffffff, 0 0 22px rgba(125,226,209,0.78);
}

.board-cell.preview-safe::after {
  background: rgba(125,226,209,0.62);
  box-shadow: inset 0 0 0 3px rgba(5,33,30,0.85);
}

.board-cell.preview-danger {
  border-color: #ffffff;
  box-shadow: 0 0 0 3px #ffffff, 0 0 22px rgba(255,122,133,0.78);
}

.board-cell.preview-danger::after {
  background: rgba(255,122,133,0.68);
  box-shadow: inset 0 0 0 3px rgba(70,10,18,0.88);
}

.board-cell.preview-out {
  border-color: #ffffff;
  box-shadow: 0 0 0 3px #ffffff, 0 0 18px rgba(255,202,104,0.72);
}

.board-cell.preview-out::after {
  background: rgba(255,202,104,0.48);
  box-shadow: inset 0 0 0 3px rgba(72,50,8,0.86);
}

.board-cell.preview-wildcard {
  border-color: #fff3bf;
  box-shadow: 0 0 0 3px #fff3bf, 0 0 22px rgba(255, 194, 64, 0.85);
}

.board-cell.preview-wildcard::after {
  background: rgba(255, 197, 76, 0.78);
  box-shadow: inset 0 0 0 3px rgba(82, 52, 0, 0.88);
}

.board-cell.preview-excavator {
  border-color: #ffd1d1;
  box-shadow: 0 0 0 3px #ffd1d1, 0 0 22px rgba(255, 122, 133, 0.82);
}

.board-cell.preview-excavator::after {
  background: rgba(255, 122, 133, 0.72);
  box-shadow: inset 0 0 0 3px rgba(70, 10, 18, 0.88);
}

.board-cell[data-preview-badge]::before {
  content: attr(data-preview-badge);
  position: absolute;
  top: 7px;
  right: 7px;
  z-index: 5;
  padding: 2px 5px;
  border-radius: 999px;
  background: rgba(8,12,17,0.9);
  color: #ffffff;
  border: 1px solid rgba(255,255,255,0.8);
  font-size: clamp(0.55rem, 1.6vw, 0.72rem);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0.02em;
  pointer-events: none;
}

.board-cell.preview-anchor {
  outline: 3px dashed rgba(255,255,255,0.95);
  outline-offset: -10px;
}

.board-cell.preview-anchor .cell-height {
  text-decoration: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 4px;
}

.board-help {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  padding: 12px 4px 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.clean-sweep-banner {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-content: center;
  gap: 4px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.82);
}

.clean-sweep-banner strong {
  font-size: clamp(1.8rem, 5vw, 4.2rem);
  line-height: 0.95;
  letter-spacing: -0.035em;
  color: #fff4b8;
  text-shadow: 0 2px 0 #8c5b00, 0 0 24px rgba(255, 210, 86, 0.9);
}

.clean-sweep-banner span {
  justify-self: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(12, 15, 20, 0.9);
  border: 1px solid rgba(255, 230, 142, 0.82);
  color: #fff7d6;
  font-size: clamp(0.78rem, 2vw, 1.05rem);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.clean-sweep-banner.show {
  animation: clean-sweep-pop 1.8s cubic-bezier(.2,.8,.2,1) both;
}

@keyframes clean-sweep-pop {
  0% { opacity: 0; transform: scale(0.72); }
  14% { opacity: 1; transform: scale(1.08); }
  28% { opacity: 1; transform: scale(1); }
  76% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.08); }
}

@media (prefers-reduced-motion: reduce) {
  .clean-sweep-banner.show { animation: clean-sweep-fade 1.8s ease both; }
  @keyframes clean-sweep-fade {
    0%, 100% { opacity: 0; }
    12%, 78% { opacity: 1; }
  }
}

.game-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 22px;
  border-radius: 18px;
  background: rgba(7, 10, 15, 0.78);
  backdrop-filter: blur(5px);
}

.game-overlay.hidden { display: none; }

.overlay-card {
  width: min(430px, 100%);
  padding: 28px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(26,31,42,0.96);
  box-shadow: var(--shadow);
}

.overlay-card h2 { margin-bottom: 10px; font-size: clamp(1.7rem, 4vw, 2.5rem); }
.overlay-card p:not(.eyebrow) { color: var(--muted); line-height: 1.5; }

.explain, .caption, .rules-short p {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.legend-cell-demo {
  position: relative;
  width: 100px;
  aspect-ratio: 1;
  margin: 14px auto 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #8a5cff, #6640c9);
  border: 1px solid #b49bff;
  border-radius: 14px;
}
.demo-number { font-size: 2rem; font-weight: 900; }
.demo-bars {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}
.caption { text-align: center; font-size: 0.75rem; }
.danger-copy { color: #ffd0d4 !important; }

.rules-dialog {
  width: min(620px, calc(100% - 28px));
  padding: 0;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.rules-dialog::backdrop { background: rgba(5,7,10,0.75); backdrop-filter: blur(4px); }
.dialog-inner { position: relative; padding: 28px; }
.dialog-inner h2 { font-size: 1.8rem; }
.dialog-inner ol { padding-left: 1.3rem; color: var(--muted); line-height: 1.6; }
.dialog-inner p { color: var(--muted); line-height: 1.55; }
.dialog-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.8rem;
  cursor: pointer;
}

@media (max-width: 1040px) {
  .game-layout { grid-template-columns: 1fr 1.6fr; }
  .legend-panel { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
  .legend-panel .panel-section { margin-top: 0; }
}

@media (max-width: 760px) {
  .shell { width: min(100% - 18px, 720px); padding-top: 16px; }
  .hero { align-items: center; }
  .hero .tagline { font-size: 0.86rem; }
  .game-layout { grid-template-columns: 1fr; }
  .board-panel { order: 1; padding: 10px; }
  .status-panel { order: 2; }
  .legend-panel { order: 3; display: block; }
  .legend-panel .panel-section { margin-top: 18px; }
  .legend-panel .panel-section:first-child { margin-top: 0; }
  .board { gap: 5px; padding: 7px; }
  .cell-bars { left: 9%; right: 9%; bottom: 8%; gap: 3%; }
  .cell-bars i { height: 3px; }
  .board-help { justify-content: flex-start; padding-left: 8px; }
}

@media (max-width: 460px) {
  .hero { align-items: flex-start; }
  .hero-actions { justify-content: flex-end; }
  .hero .button { padding: 8px 10px; font-size: 0.76rem; }
  .tagline { max-width: 240px; }
  .panel, .board-panel { border-radius: 16px; }
  .overlay-card { padding: 20px; }
}

/* v1.10 gameplay-first layout */
.shell {
  width: min(1380px, calc(100% - 24px));
  padding-top: 16px;
}

.hero {
  margin-bottom: 12px;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.5rem);
}

.game-layout {
  grid-template-columns: minmax(220px, 250px) minmax(460px, 1fr) minmax(240px, 270px);
  gap: 12px;
}

.control-panel,
.info-panel,
.board-panel {
  padding: 14px;
}

.control-panel .turn-timer {
  margin-top: 0;
}

.current-section,
.upcoming-section {
  margin-top: 12px;
}

.piece-card {
  padding: 9px;
}

.piece-preview {
  min-height: 82px;
}

.upcoming-piece {
  min-height: 72px;
  padding: 7px;
  gap: 4px;
}

.upcoming-preview {
  min-height: 36px;
}

.placement-status {
  margin-top: 12px;
  min-height: 54px;
  padding: 10px;
  font-size: 0.78rem;
}

.info-panel .first-section {
  margin-top: 0;
}

.game-stats-info {
  display: none;
}

body.game-started .pre-game-info {
  display: none;
}

body.game-started .game-stats-info {
  display: block;
}

.game-stats-info .stat-grid {
  grid-template-columns: 1fr 1fr;
}

.game-stats-info .stat-card {
  padding: 11px;
}

.game-stats-info .stat-card strong {
  font-size: 1.55rem;
}

.game-stats-info .panel-section {
  margin-top: 14px;
}

.score-key {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.74rem;
}

.score-key strong {
  color: var(--accent);
}

.board-help {
  gap: 5px 14px;
  padding-top: 8px;
  font-size: 0.7rem;
}

.leaderboard-panel {
  margin-top: 12px;
  padding: 14px 18px;
}

@media (min-width: 1041px) {
  .board-frame {
    width: min(100%, calc(100vh - 190px));
    max-width: 680px;
  }
}

@media (max-width: 1160px) and (min-width: 861px) {
  .game-layout {
    grid-template-columns: minmax(205px, 235px) minmax(420px, 1fr) minmax(220px, 250px);
    gap: 10px;
  }

  .control-panel,
  .info-panel,
  .board-panel {
    padding: 10px;
  }

  .piece-preview {
    min-height: 72px;
  }
}

@media (max-width: 1040px) {
  .game-layout {
    grid-template-columns: minmax(220px, 0.75fr) minmax(420px, 1.4fr);
  }

  .info-panel {
    grid-column: 1 / -1;
  }

  body.game-started .game-stats-info {
    display: grid;
    grid-template-columns: minmax(250px, 0.8fr) minmax(300px, 1.2fr);
    gap: 18px;
    align-items: start;
  }

  body.game-started .game-stats-info .panel-section {
    margin-top: 0;
  }

  body.game-started .score-key {
    grid-column: 1 / -1;
  }
}

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

  .board-panel { order: 1; }
  .control-panel { order: 2; }
  .info-panel { order: 3; }

  body.game-started .game-stats-info {
    display: block;
  }

  .board-frame {
    width: 100%;
  }
}


.hero h1 { text-transform: uppercase; letter-spacing: -0.02em; }
