/* Link5 - web build. Visual language ported from the SwiftUI app. */

:root {
  --bg-a: #12171a;
  --bg-b: #1f2117;
  --panel: rgba(255, 255, 255, 0.10);
  --panel-strong: rgba(255, 255, 255, 0.14);
  --hairline: rgba(255, 255, 255, 0.16);
  --board-bg: #080909;
  --cell-bg: #2e3030;
  --cell-edge: #bcc9d1;
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.72);
  --faint: rgba(255, 255, 255, 0.55);

  --p-red: #ff3b30;
  --p-blue: #0a84ff;
  --p-green: #30d158;

  --band-elite: #00c7be;
  --band-solid: #32ade6;
  --band-situational: #ff9f0a;
  --band-dangerous: #ff453a;

  --accent: #ffd60a;
  --cyan: #32d6e6;
  --radius: 8px;
}

* { box-sizing: border-box; }

/* Author display rules (e.g. buttons set to block) would otherwise override
   the browser's default [hidden] handling. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #12171a;
}

body {
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, var(--bg-a) 0%, var(--bg-b) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button, select, input { font-family: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { cursor: default; }

.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100%;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- header ---------- */

.header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand { flex: 1 1 auto; min-width: 0; }

.brand h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: -0.5px;
  line-height: 1.05;
}

.tagline {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.field-pair { display: flex; gap: 10px; }
.field-pair .field { flex: 1 1 0; min-width: 0; }

.icon-btn {
  flex: 0 0 auto;
  width: 46px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--panel-strong);
  transition: background 0.15s ease, opacity 0.15s ease;
}

.icon-btn:active { background: rgba(255, 255, 255, 0.24); }
.icon-btn:disabled { opacity: 0.4; }

/* The menu button becomes a red "leave table" while an online game is on. */
#menu-btn .icon-cancel { display: none; }
#menu-btn.is-active { background: rgba(255, 59, 48, 0.24); }
#menu-btn.is-active .icon-menu { display: none; }
#menu-btn.is-active .icon-cancel { display: block; }

/* ---------- status strip ---------- */

.status-strip { display: flex; gap: 10px; }

.status-item {
  flex: 1 1 0;
  min-width: 0;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--panel);
}

.status-item .label {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 5px;
}

.status-item .value {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

/* compact single-line status */
.status-compact {
  display: none;
  align-items: center;
  gap: 8px;
  height: 22px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.status-compact .compact-text {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-compact .deck {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.5);
}

/* ---------- board ---------- */

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

.message {
  margin: 0;
  width: 100%;
  min-height: 34px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  color: rgba(255, 255, 255, 0.78);
}

.message.is-over { color: rgba(255, 59, 48, 0.92); }

.board-frame {
  position: relative;
  width: min(100%, 50vh, 460px);
  aspect-ratio: 1 / 1;
  padding: 8px;
  border-radius: 6px;
  background: var(--board-bg);
}

.board {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  width: 100%;
  height: 100%;
}

.cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding-top: 11%;
  background: var(--cell-bg);
  box-shadow: inset 0 0 0 1.4px var(--cell-edge);
  color: #b8c2c6;
  overflow: hidden;
}

.cell .peg {
  width: 16%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.92);
}

.cell .num {
  font-size: clamp(9px, 1.55vh, 13px);
  font-weight: 900;
  line-height: 1;
}

.cell .tag {
  font-size: clamp(6px, 0.85vh, 8px);
  font-weight: 800;
  line-height: 1;
  color: rgba(255, 255, 255, 0.9);
}

.cell .hint {
  font-size: clamp(6px, 0.8vh, 8px);
  font-weight: 800;
  line-height: 1;
  color: rgba(255, 255, 255, 0.22);
}

.cell.owned {
  color: #fff;
  box-shadow: inset 0 0 0 2.4px var(--own), 0 0 5px var(--own-glow);
  background: var(--own-fill);
}

.cell.owned .peg {
  background: var(--own);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.85);
}

.cell.legal { box-shadow: inset 0 0 0 1.4px var(--cell-edge), inset 0 0 0 5px var(--accent); }
.cell.legal .hint { color: rgba(255, 255, 255, 0.7); }
.cell.threat { box-shadow: inset 0 0 0 1.4px var(--cell-edge), inset 0 0 0 5px var(--p-red); }
.cell.legal.threat { box-shadow: inset 0 0 0 1.4px var(--cell-edge), inset 0 0 0 5px var(--p-red); }

.cell.cpu-play {
  box-shadow: inset 0 0 0 4px #fff, 0 0 8px rgba(255, 255, 255, 0.95);
  z-index: 2;
}

.cell .threat-dot {
  position: absolute;
  top: 7%;
  right: 7%;
  width: 14%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: var(--p-red);
}

.cell.playable { cursor: pointer; }

.draw-overlay {
  position: absolute;
  inset: 25%;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.62);
  border: 4px solid var(--draw-color, #fff);
  box-shadow: 0 0 18px var(--draw-color, #fff);
  pointer-events: none;
  animation: pop 0.18s ease-out;
}

/* .draw-overlay sets display:grid, which would otherwise beat the browser's
   [hidden] rule and leave the overlay on screen permanently. */
.draw-overlay[hidden] { display: none; }

.draw-overlay span {
  font-size: 17vh;
  line-height: 1;
  font-weight: 900;
  color: var(--draw-color, #fff);
}

@keyframes pop {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ---------- hand ---------- */

.hand-panel {
  padding: 12px;
  border-radius: var(--radius);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hand-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.hand-title { font-size: 17px; font-weight: 700; flex: 0 0 auto; }

.hand-hint {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.62);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dead-pill {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 800;
  padding: 7px 10px;
  border-radius: var(--radius);
  background: rgba(255, 59, 48, 0.16);
}

.hand-row { display: flex; gap: 10px; align-items: stretch; }

.card {
  flex: 1 1 0;
  min-width: 0;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.22);
  box-shadow: inset 0 0 0 1px var(--hairline);
  transition: transform 0.12s ease;
}

.card .card-value { font-size: 36px; font-weight: 900; line-height: 1; }
.card .card-band { font-size: 12px; font-weight: 800; }
.card .card-count { font-size: 11px; font-weight: 800; color: rgba(255, 255, 255, 0.72); }

.card.band-elite .card-band { color: var(--band-elite); }
.card.band-solid .card-band { color: var(--band-solid); }
.card.band-situational .card-band { color: var(--band-situational); }
.card.band-dangerous .card-band { color: var(--band-dangerous); }

.card.is-dead { background: rgba(255, 59, 48, 0.2); }
.card.is-dead .card-count { color: var(--p-red); }

.card.is-selected {
  background: rgba(255, 214, 10, 0.22);
  box-shadow: inset 0 0 0 3px var(--accent);
}

.card:not(:disabled):active { transform: scale(0.97); }
.card.is-idle { opacity: 0.72; }

.card-slot {
  flex: 1 1 0;
  min-width: 0;
  min-height: 100px;
  border-radius: var(--radius);
  border: 1px dashed var(--hairline);
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.28);
}

.card-slot svg { opacity: 0.6; }

.draw-btn {
  flex: 0 0 86px;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: var(--radius);
  background: rgba(50, 214, 230, 0.28);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
  font-size: 12px;
  font-weight: 900;
}

.draw-btn:disabled {
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  opacity: 0.45;
}

/* ---------- shared form bits ---------- */

.field { display: block; margin-bottom: 12px; }

.field span {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 6px;
}

.field input, .field select {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius);
  border: 0;
  background: rgba(0, 0, 0, 0.32);
  box-shadow: inset 0 0 0 1px var(--hairline);
  font-size: 16px;
  font-weight: 600;
  outline: none;
}

.field select {
  padding-right: 36px;
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%23ffffff' stroke-opacity='0.6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  appearance: none;
  -webkit-appearance: none;
}

.field select option { background: #1b1f22; color: #fff; }
.field input:focus, .field select:focus { box-shadow: inset 0 0 0 2px var(--cyan); }

.primary-btn, .secondary-btn, .danger-btn {
  display: block;
  width: 100%;
  padding: 13px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 800;
}

.primary-btn { background: rgba(50, 214, 230, 0.3); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2); }
.secondary-btn { background: var(--panel-strong); box-shadow: inset 0 0 0 1px var(--hairline); }
.danger-btn { background: rgba(255, 59, 48, 0.22); box-shadow: inset 0 0 0 1px rgba(255, 59, 48, 0.4); }
.primary-btn:disabled, .secondary-btn:disabled { opacity: 0.45; }

/* ---------- online screens ---------- */

.screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  overflow-y: auto;
  background: linear-gradient(135deg, var(--bg-a) 0%, var(--bg-b) 100%);
}

.screen[hidden] { display: none; }

.screen-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  padding-top: max(20px, env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.room-inner { max-width: 460px; align-items: stretch; text-align: center; }

.screen-head { display: flex; align-items: flex-start; gap: 12px; }
.screen-head .screen-logo { flex: 1 1 auto; text-align: left; }

.screen-logo {
  margin: 4px 0 2px;
  font-size: clamp(30px, 6vw, 40px);
  font-weight: 900;
  letter-spacing: -0.5px;
  text-align: center;
}

.screen-logo span { color: var(--cyan); }

.panel {
  padding: 16px;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--hairline);
}

.name-panel { padding: 14px 16px; }

.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.lobby-card { display: flex; flex-direction: column; gap: 4px; }

.lobby-card h2 {
  margin: 0 0 10px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.lobby-note {
  margin: 2px 0 12px;
  font-size: 12px;
  color: var(--faint);
  line-height: 1.4;
}

.field-label {
  margin: 12px 0 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--faint);
}

.join-row { display: flex; gap: 8px; }

.join-row input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 12px;
  border-radius: var(--radius);
  border: 0;
  background: rgba(0, 0, 0, 0.32);
  box-shadow: inset 0 0 0 1px var(--hairline);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  outline: none;
}

.join-row input:focus { box-shadow: inset 0 0 0 2px var(--cyan); }
.join-row .secondary-btn { width: auto; padding: 12px 22px; }

.tables-list { display: flex; flex-direction: column; gap: 8px; min-height: 60px; }

.tables-empty {
  padding: 14px 6px;
  font-size: 13px;
  color: var(--faint);
  font-style: italic;
}

.table-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.24);
  box-shadow: inset 0 0 0 1px var(--hairline);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  transition: background 0.12s ease;
}

.table-row:hover { background: rgba(255, 255, 255, 0.08); }

.table-row .t-name {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-row .t-seats { flex: 0 0 auto; font-size: 12px; color: var(--muted); }

.table-row .t-code {
  flex: 0 0 auto;
  font-weight: 900;
  letter-spacing: 0.14em;
  color: var(--cyan);
  font-size: 13px;
}

/* ---------- start screen ---------- */

.home-inner {
  max-width: 420px;
  min-height: 100%;
  justify-content: center;
  /* Bias the block slightly above centre so it reads as a title screen. */
  padding-bottom: 12vh;
  text-align: center;
  gap: 20px;
}

.home-head { margin-bottom: 2px; }

.home-logo {
  margin: 0;
  font-size: clamp(46px, 12vw, 64px);
  font-weight: 900;
  letter-spacing: -1.5px;
  line-height: 1;
  background: linear-gradient(120deg, #fff 30%, var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.home-tagline {
  margin: 10px auto 0;
  max-width: 320px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--muted);
}

.home-panel { text-align: left; }

.home-note {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--faint);
  line-height: 1.4;
}

.home-btns { display: flex; flex-direction: column; gap: 10px; }
.home-start { padding: 16px; font-size: 17px; }

.home-rules {
  margin: 0;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--faint);
}

/* ---------- room ---------- */

.code-box { display: flex; flex-direction: column; gap: 2px; }
.code-box .field-label { margin-top: 0; }

.room-code {
  margin: 4px auto 6px;
  padding: 14px 22px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.32);
  box-shadow: inset 0 0 0 1px var(--hairline);
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  color: var(--cyan);
  transition: transform 0.1s ease;
}

.room-code:active { transform: scale(0.97); }

.room-name-line { margin: 0; font-size: 14px; font-weight: 700; color: var(--muted); min-height: 18px; }

.seat-list { display: flex; flex-direction: column; gap: 8px; }

.seat-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--hairline);
  text-align: left;
}

.seat-chip .av {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 16px;
  background: var(--seat-color, rgba(255, 255, 255, 0.14));
  color: #fff;
}

.seat-chip.empty .av { background: rgba(255, 255, 255, 0.08); color: var(--faint); }

.seat-chip .who { flex: 1 1 auto; min-width: 0; }

.seat-chip .nm {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seat-chip.empty .nm { color: var(--faint); font-weight: 600; }

.seat-chip .role { font-size: 11.5px; color: var(--faint); font-weight: 600; }

.seat-chip .stars {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
}

.host-controls { text-align: left; }
.host-controls .field { margin-bottom: 0; }

.room-btns {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.room-btns .primary-btn, .room-btns .danger-btn { width: auto; padding: 13px 26px; }

.wait-line {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  animation: waitPulse 1.6s ease-in-out infinite;
}

@keyframes waitPulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }

/* ---------- online game over ---------- */

.over-backdrop {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.66);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.over-backdrop[hidden] { display: none; }

.over-panel {
  width: 100%;
  max-width: 400px;
  background: #1a1f22;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  padding: 22px 18px;
}

.over-title { font-size: 30px; font-weight: 900; letter-spacing: -0.5px; }
.over-title.win { color: var(--accent); }
.over-sub { font-size: 14px; color: var(--muted); line-height: 1.4; margin-top: -6px; }

.standings { display: flex; flex-direction: column; gap: 8px; }

.standing-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 14px;
  font-weight: 700;
  text-align: left;
}

.standing-row .nm { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standing-row .stars { color: var(--accent); font-weight: 800; }
.standing-row.winner { box-shadow: inset 0 0 0 2px var(--accent); }

.sheet-error { margin: 12px 0 0; font-size: 13px; font-weight: 600; color: var(--p-red); }
.sheet-error[hidden] { display: none; }


/* ---------- compact / phone ---------- */

@media (max-width: 560px), (max-height: 720px) {
  .app { padding: 8px; gap: 6px; padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }

  .header { gap: 8px; height: 32px; }
  .brand h1 { font-size: 20px; }
  .tagline { display: none; }
  .icon-btn { width: 34px; height: 32px; }

  .status-strip > .status-item { display: none; }
  .status-compact { display: flex; }

  .board-frame { width: min(100%, 60vh, 410px); }
  .message { min-height: 22px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .board-area { gap: 5px; }

  .hand-panel { padding: 8px; gap: 6px; margin-top: auto; }
  .hand-title { display: none; }
  .hand-hint { font-size: 12px; font-weight: 600; color: rgba(255, 255, 255, 0.66); }
  .hand-row { gap: 6px; }
  .card, .card-slot, .draw-btn { min-height: 82px; }
  .draw-btn { flex-basis: 62px; font-size: 10px; }
  .card { gap: 3px; }
  .card .card-value { font-size: 28px; }
  .card .card-band { font-size: 10px; }
  .draw-overlay span { font-size: 14vh; }
}

@media (min-width: 561px) and (min-height: 721px) {
  .status-compact { display: none; }
}
