.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

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

#app {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.page {
  display: flex;
  width: min(100%, 480px);
  height: 100%;
  min-height: 0;
  flex-direction: column;
  margin: 0 auto;
  padding: 0 0 calc(6px + var(--safe-bottom));
  overflow: hidden;
}

.appbar {
  grid-template-columns: minmax(44px, 1fr) minmax(0, auto) minmax(74px, 1fr);
  gap: 6px;
  min-height: calc(54px + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  flex: 0 0 auto;
}
.appbar__spacer { grid-column: 1; }
.appbar__title {
  font-size: 23px;
  line-height: 1.05;
  letter-spacing: 0.055em;
}
.appbar__title small { margin-top: 2px; font-size: 10px; }
.btn--restart {
  grid-column: 3;
  justify-self: end;
  min-width: 74px;
  padding-inline: 9px;
  font-size: var(--fs-sm);
}

.turn-card {
  display: flex;
  align-items: center;
  gap: 11px;
  width: min(calc(100% - 28px), 390px);
  min-height: 58px;
  margin: 4px auto 8px;
  padding: 8px 10px;
  border: 1px solid var(--gold-500);
  border-left: 5px solid var(--gold-500);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  flex: 0 0 auto;
}
.turn-mark {
  width: 13px;
  height: 13px;
  flex: none;
  border: 2px solid rgba(38, 21, 10, 0.42);
  border-radius: 50%;
}
.turn-mark.blue { background: #3973ad; box-shadow: 0 0 0 4px rgba(57, 115, 173, 0.14); }
.turn-mark.red { background: #b9473b; box-shadow: 0 0 0 4px rgba(185, 71, 59, 0.14); }
.turn-mark.green { background: #477b52; box-shadow: 0 0 0 4px rgba(71, 123, 82, 0.14); }
.turn-mark.yellow { background: #d3a72e; box-shadow: 0 0 0 4px rgba(211, 167, 46, 0.16); }
.turn-copy {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  line-height: 1.2;
}
.turn-copy strong { color: var(--fg-strong); font-size: var(--fs-md); }
.turn-copy small { margin-top: 3px; color: var(--fg-muted); font-size: 12px; line-height: 1.2; }
.piece-count {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  gap: 3px;
  padding: 0 7px;
  border: 1px solid var(--gold-500);
  border-radius: var(--radius-sm);
  background: var(--gold-200);
  color: var(--ink-900);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  font-variant-numeric: var(--num-tabular);
  white-space: nowrap;
}
.piece-count .icon { width: 16px; height: 16px; }

.board-holder {
  display: flex;
  width: 100%;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
}
.board {
  --board-max: 390px;
  width: min(390px, calc(100vw - 24px), calc(100dvh - var(--safe-top) - var(--safe-bottom) - 350px));
  padding: 9px;
  border-radius: 19px;
}
.board__field {
  width: 100%;
  background: var(--wood-800);
}
.board--grid .board__field {
  display: flex;
  flex-direction: column;
  aspect-ratio: 1;
  grid-template-columns: none;
  grid-template-rows: none;
  overflow: visible;
}
.board__row {
  position: relative;
  display: grid;
  min-height: 0;
  flex: 1 1 0;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  container-type: inline-size;
}
.cell-slot {
  position: relative;
  --cell-side: 10cqi;
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: visible;
}
.board--grid .cell {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
  aspect-ratio: auto;
  border-radius: 0;
}
.cell.is-corner {
  display: block;
  background: var(--wood-800);
  cursor: default;
}
.cell.base-blue { background-image: linear-gradient(rgba(57, 115, 173, 0.16), rgba(57, 115, 173, 0.16)); }
.cell.base-red { background-image: linear-gradient(rgba(185, 71, 59, 0.15), rgba(185, 71, 59, 0.15)); }
.cell.base-green { background-image: linear-gradient(rgba(71, 123, 82, 0.16), rgba(71, 123, 82, 0.16)); }
.cell.base-yellow { background-image: linear-gradient(rgba(211, 167, 46, 0.18), rgba(211, 167, 46, 0.18)); }
.board--grid .cell { background-color: transparent; background-image: none; }
.board--grid .cell::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 0;
  width: var(--cell-side);
  height: var(--cell-side);
  transform: translate(-50%, -50%);
  background-color: transparent;
  background-image: none;
  pointer-events: none;
}
.board--grid .cell--light::before { background-color: var(--cell-light); }
.board--grid .cell--dark::before { background-color: var(--cell-dark); }
.board--grid .cell.base-blue::before { background-image: linear-gradient(rgba(57, 115, 173, 0.16), rgba(57, 115, 173, 0.16)); }
.board--grid .cell.base-red::before { background-image: linear-gradient(rgba(185, 71, 59, 0.15), rgba(185, 71, 59, 0.15)); }
.board--grid .cell.base-green::before { background-image: linear-gradient(rgba(71, 123, 82, 0.16), rgba(71, 123, 82, 0.16)); }
.board--grid .cell.base-yellow::before { background-image: linear-gradient(rgba(211, 167, 46, 0.18), rgba(211, 167, 46, 0.18)); }
.board--grid .cell::after {
  inset: auto;
  top: 50%;
  left: 50%;
  width: var(--cell-side);
  height: var(--cell-side);
  transform: translate(-50%, -50%);
}
.board--grid .cell .piece { width: 7.8cqi; height: 7.8cqi; flex: none; }
.piece { width: 78%; height: 78%; border: 2px solid rgba(38, 21, 10, 0.5); }
.piece--blue { background-color: #3973ad; color: #dceaff; }
.piece--red { background-color: #b9473b; color: #ffe0d8; }
.piece--green { background-color: #477b52; color: #e0f2d8; }
.piece--yellow { background-color: #d3a72e; color: #fff4c7; }
.piece::before { opacity: 0.5; }
.cell.is-removable::after {
  opacity: 1;
  background: radial-gradient(circle, transparent 0 54%, var(--cell-capture) 56% 72%, transparent 74%);
}

.board-caption {
  width: min(calc(100% - 28px), 390px);
  min-height: 16px;
  margin: 4px auto 0;
  color: var(--fg-muted);
  font-size: 12px;
  line-height: 1.25;
  text-align: center;
}
.legend {
  display: flex;
  width: min(calc(100% - 28px), 390px);
  min-height: 18px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 13px;
  margin: 4px auto 0;
  color: var(--fg-muted);
  font-size: 12px;
  line-height: 1.2;
}
.legend-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend-selected { width: 13px; height: 13px; border: 2px solid var(--gold-500); border-radius: 3px; }
.legend-legal { width: 11px; height: 11px; border-radius: 50%; background: var(--success-500); }
.legend-capture { width: 13px; height: 13px; border: 2px solid var(--danger-500); border-radius: 50%; }
.legend-removal { width: 13px; height: 13px; border: 2px solid var(--danger-500); border-radius: 50%; }

.roster {
  display: grid;
  width: min(calc(100% - 28px), 390px);
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 9px auto 0;
}
.seat {
  display: flex;
  min-width: 0;
  min-height: 62px;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--fg-muted);
  font-size: 11px;
  line-height: 1.1;
  text-align: center;
}
.seat.is-current {
  border-color: var(--gold-500);
  background: linear-gradient(180deg, var(--surface), var(--gold-200));
  color: var(--ink-900);
  box-shadow: 0 0 0 1px var(--gold-500);
}
.seat.is-winner {
  border-color: var(--success-500);
  background: linear-gradient(180deg, var(--surface), var(--success-100));
  color: var(--success-700);
  box-shadow: 0 0 0 1px var(--success-500);
}
.seat-name { color: var(--fg-strong); font-size: 12px; font-weight: var(--fw-bold); }
.seat-count { font-variant-numeric: var(--num-tabular); white-space: nowrap; }
.seat-dot {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(38, 21, 10, 0.45);
  border-radius: 50%;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.35), 0 1px 2px rgba(38, 21, 10, 0.25);
}
.blue { background-color: #3973ad; }
.red { background-color: #b9473b; }
.green { background-color: #477b52; }
.yellow { background-color: #d3a72e; }

.order-line {
  display: flex;
  width: min(calc(100% - 28px), 390px);
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 7px auto 0;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--fg);
  font-size: var(--fs-xs);
  text-align: center;
}
.order-line .icon { width: 17px; height: 17px; flex: none; color: var(--wood-500); }
.order-line strong { color: var(--fg-strong); }
.footnote {
  margin: 5px 18px 0;
  color: var(--fg-muted);
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--space-3);
  background: var(--surface-parchment);
  color: var(--fg-strong);
}
.loading-overlay--hidden { display: none; }
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--parchment-300);
  border-top-color: var(--gold-700);
  border-radius: 50%;
  animation: quartetto-spin 0.8s linear infinite;
}
@keyframes quartetto-spin { to { transform: rotate(360deg); } }

@media (max-width: 360px) {
  .appbar { padding-inline: 9px; }
  .appbar__title { font-size: 21px; }
  .btn--restart { min-width: 68px; padding-inline: 6px; }
  .turn-card { width: calc(100% - 18px); gap: 8px; padding-inline: 8px; }
  .board-holder { padding-inline: 5px; }
  .board { width: min(390px, calc(100vw - 12px), calc(100dvh - var(--safe-top) - var(--safe-bottom) - 350px)); padding: 7px; }
  .roster { gap: 4px; }
  .seat { padding-inline: 2px; font-size: 10px; }
  .seat-name { font-size: 11px; }
  .legend { gap: 4px 9px; }
}

@media (max-height: 700px) {
  .appbar { min-height: calc(48px + var(--safe-top)); }
  .turn-card { min-height: 54px; margin-top: 2px; margin-bottom: 5px; padding-block: 6px; }
  .board {
    width: min(390px, calc(100vw - 24px), max(250px, calc(100dvh - var(--safe-top) - var(--safe-bottom) - 300px)));
    padding: 7px;
  }
  .board-caption { margin-top: 2px; }
  .legend { min-height: 16px; margin-top: 2px; }
  .roster { gap: 4px; margin-top: 5px; }
  .seat { min-height: 56px; padding-block: 4px; gap: 2px; }
  .order-line { min-height: 34px; margin-top: 2px; }
  .footnote { display: none; }
}

@media (max-height: 515px) {
  .legend { display: none; }
}

@media (max-height: 480px) {
  .order-line { display: none; }
}
