:root {
  --paper: #f5f0e8;
  --ink: #202026;
  --muted: #6a6670;
  --line: #d9d0c3;
  --panel: #fffaf1;
  --deep: #1f2430;
  --amber: #f2ad5f;
  --blue: #5aabd6;
  --green: #5fbf86;
  --coral: #e86d5a;
  --violet: #7a78d9;
  --gold: #ded26b;
  --shadow: 0 18px 50px rgba(31, 36, 48, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(135deg, rgba(90, 171, 214, 0.24), transparent 32%),
    linear-gradient(225deg, rgba(232, 109, 90, 0.18), transparent 30%),
    var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100%;
  margin: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  gap: 18px;
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0;
}

.stage,
.panel {
  border: 1px solid rgba(32, 32, 38, 0.12);
  background: rgba(255, 250, 241, 0.88);
  box-shadow: var(--shadow);
}

.stage {
  display: flex;
  min-width: 0;
  min-height: calc(100vh - 44px);
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-radius: 8px;
}

.mast,
.score-strip,
.panel-title,
.button-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4.6vw, 4.2rem);
  line-height: 0.94;
}

h2 {
  font-size: 1rem;
}

h3 {
  font-size: 0.92rem;
}

.seedbar {
  display: grid;
  grid-template-columns: auto minmax(9rem, 12rem) 2.5rem;
  align-items: center;
  gap: 8px;
}

.seedbar label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.seedbar input {
  min-width: 0;
  height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fffdf9;
  color: var(--deep);
  font-weight: 800;
  text-transform: uppercase;
}

.icon-button,
.button-row button {
  min-height: 2.5rem;
  border: 0;
  border-radius: 6px;
  background: var(--deep);
  color: #fffaf1;
  font-weight: 850;
}

.icon-button {
  width: 2.5rem;
  font-size: 1.15rem;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fffdf8;
}

.score-strip div {
  min-width: 0;
  padding: 10px 12px;
  border-left: 1px solid var(--line);
}

.score-strip div:first-child {
  border-left: 0;
}

.score-strip span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.score-strip strong {
  display: block;
  overflow: hidden;
  color: var(--deep);
  font-size: 1.2rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(7, minmax(0, 1fr));
  gap: clamp(6px, 1vw, 10px);
  width: min(100%, calc(100vh - 210px));
  max-width: 820px;
  min-width: 320px;
  aspect-ratio: 1;
  margin: auto;
  padding: clamp(8px, 1vw, 12px);
  border: 1px solid rgba(32, 32, 38, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(45deg, rgba(32, 36, 48, 0.055) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(32, 36, 48, 0.055) 25%, transparent 25%),
    #eee5d6;
  background-size: 18px 18px;
}

.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(32, 32, 38, 0.1);
  border-radius: 7px;
  background: rgba(255, 253, 248, 0.74);
  color: rgba(32, 32, 38, 0.35);
  overflow: hidden;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.cell:hover {
  transform: translateY(-1px);
}

.cell.void {
  opacity: 0.48;
}

.cell.valid {
  border-color: rgba(31, 36, 48, 0.55);
  box-shadow: inset 0 0 0 2px rgba(255, 250, 241, 0.95), 0 8px 20px rgba(31, 36, 48, 0.12);
}

.cell.filled {
  background:
    radial-gradient(circle at 74% 18%, color-mix(in srgb, var(--tile-accent), white 18%) 0 12%, transparent 13%),
    linear-gradient(145deg, color-mix(in srgb, var(--tile), white 22%), var(--tile));
  color: var(--tile-ink);
  box-shadow: inset 0 -10px 18px rgba(0, 0, 0, 0.08);
}

.motif-ring {
  position: absolute;
  inset: 10%;
  border: 2px solid color-mix(in srgb, var(--tile-accent), white 10%);
  border-radius: 999px;
  opacity: 0.64;
}

.motif-keystone .motif-ring,
.motif-quiet .motif-ring {
  border-radius: 4px;
  transform: rotate(45deg) scale(0.78);
}

.motif-court .motif-ring {
  inset: 18%;
  box-shadow: 0 0 0 10px rgba(255, 255, 255, 0.16);
}

.motif-mirror .motif-ring {
  border-style: double;
}

.motif-edge .motif-ring {
  inset: 7%;
  border-width: 3px;
}

.glyph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: Georgia, serif;
  font-size: clamp(1.1rem, 4.5vw, 3rem);
  font-weight: 900;
}

.tile-name,
.turn-dot,
.coord {
  position: absolute;
  z-index: 2;
  font-weight: 900;
}

.tile-name {
  left: 7px;
  bottom: 5px;
  font-size: clamp(0.55rem, 1.2vw, 0.78rem);
}

.turn-dot {
  right: 5px;
  top: 5px;
  display: grid;
  width: clamp(1rem, 2vw, 1.35rem);
  aspect-ratio: 1;
  place-items: center;
  border-radius: 999px;
  background: rgba(255, 250, 241, 0.78);
  font-size: clamp(0.5rem, 1vw, 0.68rem);
}

.coord {
  right: 6px;
  bottom: 6px;
  font-size: 0.64rem;
}

.side {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 14px;
}

.panel {
  border-radius: 8px;
  padding: 14px;
}

.panel-title {
  margin-bottom: 12px;
}

.panel-title span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.pulse {
  animation: pulse 460ms ease;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

.hand {
  display: grid;
  gap: 10px;
}

.card {
  display: grid;
  grid-template-columns: 4.2rem minmax(0, 1fr);
  gap: 10px;
  min-height: 7.2rem;
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 10px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.74), rgba(255, 250, 241, 0.9)),
    color-mix(in srgb, var(--tile), white 34%);
  color: var(--tile-ink);
  text-align: left;
}

.card.selected {
  border-color: var(--deep);
  box-shadow: 0 10px 25px rgba(31, 36, 48, 0.18);
}

.card-top {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-top strong {
  font-size: 1rem;
}

.card-top em {
  color: color-mix(in srgb, var(--tile-ink), white 22%);
  font-size: 0.78rem;
  font-style: normal;
  font-weight: 900;
}

.mini-tile {
  display: grid;
  min-width: 0;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 7px;
  background: var(--tile);
  box-shadow: inset 0 -10px 18px rgba(0, 0, 0, 0.08);
  font-family: Georgia, serif;
  font-size: 2rem;
  font-weight: 900;
}

.card-copy {
  align-self: center;
  color: color-mix(in srgb, var(--tile-ink), black 8%);
  font-size: 0.85rem;
  font-weight: 720;
  line-height: 1.28;
}

.contracts {
  display: grid;
  gap: 10px;
}

.contract {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fffdf8;
}

.contract p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.32;
}

.contract strong {
  min-width: 2.2rem;
  border-radius: 6px;
  padding: 5px 7px;
  background: var(--deep);
  color: #fffaf1;
  text-align: center;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 12px;
}

.button-row button {
  padding: 0 12px;
}

.button-row button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.log {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 1.25rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(31, 36, 48, 0.42);
}

.finish {
  border: 1px solid rgba(32, 32, 38, 0.16);
  border-radius: 8px;
  padding: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.finish h2 {
  margin-bottom: 6px;
  font-size: 1.8rem;
}

.finish p + p {
  margin-bottom: 18px;
  color: var(--muted);
  font-weight: 800;
}

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

  .stage {
    min-height: auto;
  }

  .board {
    width: min(100%, 84vh);
  }

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

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

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

  .card {
    grid-template-columns: 3rem minmax(0, 1fr);
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 18px, 560px);
    padding: 9px 0;
  }

  .stage,
  .panel {
    padding: 10px;
  }

  .mast {
    align-items: stretch;
    flex-direction: column;
  }

  .seedbar {
    grid-template-columns: auto minmax(0, 1fr) 2.5rem;
  }

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

  .score-strip div {
    border-top: 1px solid var(--line);
  }

  .score-strip div:nth-child(1),
  .score-strip div:nth-child(2) {
    border-top: 0;
  }

  .score-strip div:nth-child(3),
  .score-strip div:nth-child(5) {
    border-left: 0;
  }

  .score-strip div:nth-child(5) {
    grid-column: 1 / -1;
  }

  .board {
    min-width: 0;
    gap: 5px;
    padding: 7px;
  }

  .side,
  .hand {
    grid-template-columns: 1fr;
  }

  .card {
    min-height: 6.4rem;
  }
}
