:root {
  --bg: #090b0f;
  --bg-elev: #12161e;
  --bg-soft: #1a202c;
  --line: #2b3342;
  --text: #eef2f7;
  --muted: #8b94a7;
  --accent: #e8b86d;
  --accent-dim: #8a6b32;
  --legal: #3ad29a;
  --threat: #ff6a3d;
  --hex: #1e2736;
  --hex-hover: #2a3548;
  --white: #f4efe4;
  --black: #0c0e12;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body, #app {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body {
  font-family: "EB Garamond", "Palatino Linotype", Palatino, "Times New Roman", serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

h1, h2, h3, .hero .eyebrow, .topbar [data-action="menu"] {
  font-family: Cinzel, "EB Garamond", "Times New Roman", serif;
}

button, select {
  font: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

button.primary {
  background: var(--accent);
  color: #1a1208;
  border-color: var(--accent);
  width: 100%;
  padding: 0.65rem 1rem;
  font-weight: 600;
}

button.ghost {
  background: transparent;
}

a {
  color: var(--accent);
}

.screen {
  height: 100%;
  overflow: hidden;
}

.text-screen {
  overflow: auto;
  max-width: 40rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 2rem;
}

.menu {
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 36rem;
  margin: 0 auto;
  padding: clamp(0.6rem, 2.4vh, 1.6rem) 1.15rem;
  overflow: hidden;
}

.hero .eyebrow {
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 700;
}

.hero h1 {
  font-size: clamp(1.85rem, 5.4vh, 3.2rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 0.95;
  margin: 0.3rem 0 0.45rem;
}

.lede, .text-screen p, .text-screen li {
  line-height: 1.45;
  color: var(--muted);
}

.menu .lede {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.challenge, .text-screen ol {
  margin-top: 1.1rem;
}

.challenge {
  display: grid;
  gap: 0.55rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  border-radius: 1rem;
}

.challenge h2 {
  font-size: 1rem;
  font-weight: 700;
}

.challenge label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.challenge select {
  padding: 0.4rem 0.65rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
}

.menu-secondary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-top: 0.7rem;
}

.menu-secondary button {
  width: 100%;
}

.menu-secondary button,
.back {
  background: transparent;
}

.text-screen h1 {
  margin: 1rem 0;
  letter-spacing: -0.03em;
}

.text-screen ol {
  padding-left: 1.15rem;
  display: grid;
  gap: 0.65rem;
}

.historia .eyebrow {
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 0.7rem;
  color: var(--accent);
  font-family: Cinzel, "EB Garamond", serif;
}

.historia p + p {
  margin-top: 0.75rem;
}

.historia-cierre {
  margin-top: 1.1rem;
  color: var(--text);
  font-style: italic;
}

.game {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--line);
  min-height: 0;
}

.topbar [data-action="menu"] {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  border: 0;
  background: transparent;
  padding: 0.2rem 0;
}

.topbar-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.hud-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
  flex: 1;
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 0;
}

.hud-inline strong {
  color: var(--text);
  font-family: Cinzel, "EB Garamond", "Times New Roman", serif;
}

.hud-chip,
.hud-meter,
.hud-qudak {
  white-space: nowrap;
}

.hud-meter.foe {
  color: #f0a08c;
}

.reserve-count,
.controls p {
  font-size: 0.75rem;
  color: var(--muted);
}

.flash {
  color: var(--threat);
}

.table {
  display: grid;
  grid-template-columns: minmax(7.5rem, 14vw) 1fr minmax(7.5rem, 14vw);
  align-items: stretch;
  min-height: 0;
  overflow: hidden;
}

.board-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  padding: 0.15rem;
  min-width: 0;
  min-height: 0;
}

.board {
  position: relative;
}

.hex-flop {
  position: absolute;
}

.hex-flop.is-origin-flop {
  z-index: 8;
}

.hex-cell {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--hex);
  clip-path: polygon(50% 0, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%);
}

.hex-cell:hover {
  background: var(--hex-hover);
}

.hex-cell svg {
  width: 88%;
  height: 88%;
}

.hex-cell .hex-label {
  font-size: 0.62rem;
  color: #6d778c;
  font-weight: 600;
}

.hex-cell.is-legal {
  background: #174536;
}

.hex-cell.is-move-target {
  background: #1f5d3f;
  box-shadow: inset 0 0 0 2px var(--legal);
}

.hex-cell.is-movable:not(.is-origin) {
  box-shadow: inset 0 0 0 1px var(--accent-dim);
}

.hex-cell.is-threatened {
  box-shadow: inset 0 0 0 2px var(--threat);
}

.hex-cell.is-origin {
  background: #3a2d16;
}

.reserve {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-elev);
  border: 0 solid var(--line);
  padding: 0.45rem 0.3rem 0.3rem;
  overflow: hidden;
}

.reserve-black {
  border-right-width: 1px;
}

.reserve-white {
  border-left-width: 1px;
}

.reserve h2 {
  font-size: 0.95rem;
  text-align: center;
  font-weight: 700;
}

.reserve-count {
  text-align: center;
  margin-top: 0.15rem;
}

.reserve-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: 0.12rem 0.15rem;
  margin-top: 0.35rem;
  padding: 0.1rem 0.35rem 0.15rem;
  overflow: hidden;
}

.piece-flop {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
  height: 100%;
}

.piece {
  position: relative;
  width: min(100%, 5.4rem);
  max-height: 100%;
  aspect-ratio: 1 / 1.05;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  clip-path: polygon(50% 0, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%);
}

.piece svg {
  display: block;
  width: 100%;
  height: 100%;
}

.piece-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10%;
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: center;
  color: var(--white);
}

.piece.white .piece-name {
  color: var(--black);
}

.piece-flop.is-locked {
  opacity: 0.32;
}

.piece-flop.is-playable .piece {
  box-shadow: 0 0 0 1px var(--accent-dim);
}

.piece-flop.is-selected {
  z-index: 6;
}

.flop-rot {
  position: absolute;
  top: 50%;
  z-index: 9;
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  transform: translateY(-50%);
}

.flop-rot svg {
  width: 1rem;
  height: 1rem;
}

.flop-rot.left {
  left: -0.15rem;
}

.flop-rot.right {
  right: -0.15rem;
}

.hex-flop .flop-rot.left {
  left: -0.2rem;
}

.hex-flop .flop-rot.right {
  right: -0.2rem;
}

.flop-remove {
  position: absolute;
  left: 50%;
  bottom: 0.05rem;
  transform: translateX(-50%);
  z-index: 9;
  padding: 0.15rem 0.5rem;
  font-size: 0.68rem;
  background: #3a1712;
  color: #ffb4a4;
  border-color: #6a2b22;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.75rem 0.45rem;
  border-top: 1px solid var(--line);
  background: var(--bg);
  min-height: 0;
}

.controls p {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.victory {
  color: var(--accent);
}

@media (max-width: 899px) {
  .table {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 15vh) minmax(0, 1fr) minmax(0, 15vh);
  }

  .hud-inline {
    display: none;
  }

  .reserve {
    border-width: 0;
  }

  .reserve-black {
    border-bottom-width: 1px;
    order: -1;
  }

  .reserve-white {
    border-top-width: 1px;
  }

  .reserve-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 0.1rem;
    padding: 0.1rem 0.45rem;
  }

  .board-wrap {
    min-height: 0;
  }

  .piece {
    width: min(100%, 3.4rem);
  }
}
