/* Line of Five - first-party game styles. */

:root {
  --bg: #0b1322;
  --bg-2: #101c33;
  --panel: #152238;
  --panel-2: #1c2c47;
  --line: rgba(255, 255, 255, 0.09);
  --text: #eef3ff;
  --muted: #9fb0d0;
  --accent: #ffd166;
  --accent-2: #4f8cff;
  --danger: #ff5d75;
  --card: #fbfaf4;
  --card-ink: #1b1f2a;
  --card-red: #d11f3a;
  --p0: #4f8cff;
  --p1: #ff8a3d;
  --p2: #35c47a;
  --radius: 14px;
  --font: "Trebuchet MS", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-display: "Arial Black", "Avenir Next Condensed", Impact, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* The portal bridge pins <body> to the viewport, so the app scrolls inside. */
#app {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(circle at 10% 0%, rgba(79, 140, 255, 0.18), transparent 36%),
    radial-gradient(circle at 90% 100%, rgba(255, 138, 61, 0.14), transparent 32%),
    var(--bg);
}

h1, h2, h3 { margin: 0; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }

.screen { min-height: 100%; }
.screen[hidden] { display: none; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #1a1400;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}
.button:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(255, 209, 102, 0.25); }
.button:active { transform: translateY(0); }
.button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
.button--ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.22);
}
.button--ghost:hover { box-shadow: none; background: rgba(255, 255, 255, 0.06); }
.button--small { min-height: 36px; padding: 6px 14px; font-size: 0.9rem; }
.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link:hover { color: var(--text); }

/* --------------------------------------------------------- menu/lobby */

.screen--menu, .screen--lobby {
  display: grid;
  place-items: start center;
  padding: 24px 16px 48px;
}

.menu-card {
  width: min(720px, 100%);
  background: rgba(21, 34, 56, 0.9);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px 24px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(10px);
}

.menu-head { text-align: center; margin-bottom: 20px; }
.brand {
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 700;
}
.title {
  font-family: var(--font-display);
  font-size: clamp(2.1rem, 6vw, 3.4rem);
  line-height: 1.05;
  margin: 6px 0 10px;
}
.title--code { letter-spacing: 0.18em; }
.tagline { color: var(--muted); max-width: 48ch; margin: 0 auto; }

.field { margin: 0 0 18px; }
.field label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 6px; }
.field input, .option-names input, #join-code, #lobby-link {
  width: 100%;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  outline: none;
}
.field input:focus, .option-names input:focus, #join-code:focus { border-color: var(--accent-2); }
.field--inline { display: flex; gap: 10px; }
.field--inline input { flex: 1; min-width: 0; font-size: 0.85rem; }

.invite {
  background: rgba(79, 140, 255, 0.15);
  border: 1px solid rgba(79, 140, 255, 0.4);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 18px;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.option {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.option--wide { grid-column: 1 / -1; }
.option h2 { font-size: 1.05rem; }
.option p { color: var(--muted); font-size: 0.92rem; line-height: 1.45; }
.option-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: auto; }
.option-actions--online { align-items: center; }
.option-actions--online #join-code {
  flex: 1;
  min-width: 140px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 700;
}
.or { color: var(--muted); font-size: 0.85rem; }
.option-names { display: grid; gap: 8px; max-height: 232px; overflow-y: auto; padding-right: 2px; }
.option-names label { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); }
.option-names label > span { display: inline-flex; align-items: center; gap: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.option-names .player-dot { width: 10px; height: 10px; flex: none; }
.option-names label.chip-p0 .player-dot { background: var(--p0); }
.option-names label.chip-p1 .player-dot { background: var(--p1); }
.option-names label.chip-p2 .player-dot { background: var(--p2); }
.option-names input { min-height: 38px; }

/* ----------------------------------------------------- match settings */

.settings { gap: 12px; }
.settings-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 14px; }
.settings-summary { color: var(--accent); font-size: 0.88rem; font-weight: 700; }
.settings-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.settings--lobby { margin: 14px 0 6px; }
.settings--lobby .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.setting { display: grid; gap: 6px; }
.setting-label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.segs { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.12); }
.seg {
  flex: 1;
  min-width: 34px;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  transition: background 120ms ease, color 120ms ease;
}
.seg:hover { color: var(--text); }
.seg.is-on { background: var(--accent); color: #1a1400; }
.seg:disabled { opacity: 0.3; cursor: not-allowed; }
.lobby-summary { text-align: center; margin-top: 8px; }
.menu-foot { text-align: center; margin-top: 18px; }
.menu-note { margin-top: 12px; text-align: center; font-size: 0.82rem; }

/* The play stack: the main button first and biggest, create a room second. */
.play-stack { display: grid; gap: 10px; margin: 4px 0 18px; }
.button--hero, .button--second {
  width: 100%; justify-content: flex-start; text-align: left; border-radius: 16px; padding: 14px 18px; gap: 14px;
}
.button--hero { min-height: 76px; font-size: 1.1rem; box-shadow: 0 12px 34px rgba(255, 209, 102, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.35); }
.button--hero:hover { box-shadow: 0 16px 40px rgba(255, 209, 102, 0.4); }
.button--second {
  min-height: 60px; background: rgba(255, 255, 255, 0.08); color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.22);
}
.button--second:hover { background: rgba(255, 255, 255, 0.13); box-shadow: none; }
.hero-icon { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: rgba(0, 0, 0, 0.18); font-size: 1.2rem; flex: none; }
.hero-text { display: grid; gap: 2px; min-width: 0; }
.hero-text strong { font-size: 1.15em; line-height: 1.1; }
.hero-text small { font-weight: 600; font-size: 0.78rem; opacity: 0.82; line-height: 1.3; }
.button--second .hero-text small { color: var(--muted); }
.join-row { display: flex; gap: 10px; align-items: center; }
.join-row #join-code { flex: 1; min-width: 120px; text-transform: uppercase; letter-spacing: 0.14em; font-weight: 700; }
.muted { color: var(--muted); font-size: 0.9rem; }

/* ------------------------------------------------------------ players */

.players { display: grid; gap: 6px; }
.players--lobby { margin: 18px 0; }
.player {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
}
.player.is-turn { border-color: rgba(255, 209, 102, 0.7); background: rgba(255, 209, 102, 0.08); }
.player.is-offline { opacity: 0.6; }
.player--empty { opacity: 0.5; border-style: dashed; border-color: var(--line); }
.player-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--muted); }
.player.chip-p0 .player-dot { background: var(--p0); }
.player.chip-p1 .player-dot { background: var(--p1); }
.player.chip-p2 .player-dot { background: var(--p2); }
.player-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-meta { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }

/* A team with more than one seat: a coloured header, then its members. */
.team {
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  padding: 6px 6px 6px;
}
.team.is-turn { border-color: rgba(255, 209, 102, 0.35); }
.team-head {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 6px;
}
.team.chip-p0 .team-head .player-dot { background: var(--p0); }
.team.chip-p1 .team-head .player-dot { background: var(--p1); }
.team.chip-p2 .team-head .player-dot { background: var(--p2); }
.team-name { font-weight: 700; }
.team-members { display: grid; gap: 4px; }
.team-members .player { padding: 6px 10px; background: rgba(255, 255, 255, 0.04); }
.team-members .player .player-dot { width: 8px; height: 8px; margin-left: 3px; opacity: 0.8; }

/* --------------------------------------------------------------- game */

.screen--game { display: flex; flex-direction: column; min-height: 100%; }

.game-bar-actions { display: inline-flex; gap: 6px; align-items: center; }
.button--icon { min-width: 36px; padding: 6px 8px; font-size: 1rem; line-height: 1; }
.button--icon.is-off { opacity: 0.6; }
.menu-foot .link { display: inline-flex; align-items: center; gap: 4px; }
.menu-foot-sep { color: var(--muted); margin: 0 8px; }

.game-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 19, 34, 0.9);
  position: sticky;
  top: 0;
  z-index: 5;
}
.status { text-align: center; font-weight: 700; font-size: 0.95rem; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  flex: 1;
}

.board-wrap { display: grid; place-items: center; }

.board {
  --cell-font: clamp(8px, 2.3vmin, 15px);
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 3px;
  width: min(100%, calc(100vh - 290px));
  min-width: 260px;
  aspect-ratio: 1 / 1;
  padding: 6px;
  border-radius: 12px;
  background: #0d3b2b;
  background-image: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.08), transparent 50%);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35), 0 20px 50px rgba(0, 0, 0, 0.4);
}

.cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: var(--card);
  color: var(--card-ink);
  font-size: var(--cell-font);
  line-height: 1;
  font-weight: 700;
  min-width: 0;
  aspect-ratio: 1 / 1;
  transition: box-shadow 120ms ease, transform 120ms ease;
}
.cell[aria-disabled="true"] { cursor: default; }
.cell--red { color: var(--card-red); }
.cell--corner { background: #e9d58e; color: #6b4e00; font-size: calc(var(--cell-font) * 1.5); }
.card-rank { font-size: 1em; }
.card-suit { font-size: 0.95em; margin-top: 1px; }
.cell-free { font-size: 1em; }

.cell.is-match { box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.9); }

/* Three strengths of "you can go here": any card (subtle), the hovered card
   (medium), the selected card (strong). */
.cell.is-playable {
  cursor: pointer;
  box-shadow: 0 0 0 1.5px rgba(255, 209, 102, 0.55);
}
.cell.is-playable:hover { transform: scale(1.08); box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.9), 0 0 10px rgba(255, 209, 102, 0.5); z-index: 1; }
.cell.is-preview {
  background: #fff6d6;
  transform: scale(1.06);
  box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.95), 0 0 10px rgba(255, 209, 102, 0.55);
  z-index: 1;
}
.cell.is-legal {
  background: #fff1bd;
  box-shadow: 0 0 0 2px var(--accent), 0 0 12px rgba(255, 209, 102, 0.8);
  cursor: pointer;
  z-index: 1;
}
.cell.is-legal:hover { transform: scale(1.08); }
.cell.is-twin { outline: 2px dashed rgba(255, 255, 255, 0.85); outline-offset: -2px; z-index: 1; }
.cell.is-last { box-shadow: 0 0 0 2px #ffffff; }
.cell.is-legal.is-last { box-shadow: 0 0 0 2px var(--accent), 0 0 12px rgba(255, 209, 102, 0.8); }
.cell.is-playable.is-last { box-shadow: 0 0 0 2px #ffffff, 0 0 0 3.5px rgba(255, 209, 102, 0.55); }

/* The selected card's squares pulse gently so they read on a crowded board. */
.cell.is-legal:not(.has-chip) { animation: lof-pulse 1.4s ease-in-out infinite; }
@keyframes lof-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--accent), 0 0 8px rgba(255, 209, 102, 0.5); }
  50% { box-shadow: 0 0 0 3px var(--accent), 0 0 16px rgba(255, 209, 102, 0.95); }
}

/* A chip just placed drops in; a cut chip would simply vanish on re-render. */
.cell.has-chip.is-last::after { animation: lof-drop 220ms cubic-bezier(0.2, 0.9, 0.3, 1.3); }
@keyframes lof-drop {
  from { transform: scale(1.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.cell.has-chip::after {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  background: var(--chip, #888);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.28), inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 2px 4px rgba(0, 0, 0, 0.45);
}
.cell.has-chip.chip-p0 { --chip: var(--p0); }
.cell.has-chip.chip-p1 { --chip: var(--p1); }
.cell.has-chip.chip-p2 { --chip: var(--p2); }
.cell.has-chip .card-rank, .cell.has-chip .card-suit { opacity: 0.35; }
.cell.is-locked::before {
  content: "";
  position: absolute;
  inset: 32%;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.95);
  z-index: 2;
}
/* A cut target is a chip you may click, so make the chip itself glow. */
.cell.has-chip.is-legal::after { box-shadow: 0 0 0 2px #fff, 0 0 10px #fff; }

/* -------------------------------------------------------------- panel */

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: rgba(21, 34, 56, 0.75);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.panel h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.hand-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.hand {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 2px 4px;
  min-height: 90px;
  scrollbar-width: thin;
}
.hand-card {
  position: relative;
  flex: 0 0 auto;
  width: 56px;
  height: 78px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  border-radius: 8px;
  background: var(--card);
  color: var(--card-ink);
  font-weight: 800;
  font-size: 1.1rem;
  line-height: 1;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}
.hand-card--red { color: var(--card-red); }
.hand-card--wild { background: linear-gradient(160deg, #fff7d6, #ffe08a); }
.hand-card--cut { background: linear-gradient(160deg, #ffe3e8, #ffb3c0); }
.hand-card.is-dead { opacity: 0.55; }
.hand-card:not(:disabled):hover { transform: translateY(-4px); box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.8), 0 8px 16px rgba(0, 0, 0, 0.4); }
.hand-card.is-hinted { transform: translateY(-4px); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9), 0 8px 16px rgba(0, 0, 0, 0.4); }
.hand-card.is-selected, .hand-card.is-selected:hover { transform: translateY(-8px); box-shadow: 0 0 0 3px var(--accent), 0 10px 20px rgba(0, 0, 0, 0.45); }
.hand-card:disabled { cursor: default; opacity: 0.6; }
.hand-card .card-suit { font-size: 1.05rem; }
.hand-tag {
  position: absolute;
  bottom: 4px;
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #5b4a00;
  font-weight: 700;
}
.hand-card.is-dead .hand-tag { color: #7a1f2e; }
.hand-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.takeover { display: grid; gap: 6px; }
.takeover:empty { display: none; }

.log { display: grid; gap: 4px; font-size: 0.82rem; color: var(--muted); }
.log li { padding-left: 10px; border-left: 2px solid var(--line); }

/* ------------------------------------------------------------- modals */

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 9, 18, 0.72);
  backdrop-filter: blur(4px);
}
.modal-card {
  width: min(440px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px;
  text-align: center;
  display: grid;
  gap: 12px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
.modal-card--wide { width: min(600px, 100%); text-align: left; }
.modal-card h2 { font-size: 1.5rem; }
.modal-card p { color: var(--muted); }
.modal-card .option-actions { justify-content: center; }
.rules { display: grid; gap: 10px; padding-left: 22px; list-style: decimal; color: var(--text); line-height: 1.5; }
.rules li { padding-left: 4px; }
.rules strong { color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 20px);
  z-index: 30;
  padding: 10px 16px;
  border-radius: 999px;
  background: #223457;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast--good { background: #1f7a4d; }
.toast--warn { background: #8a3b2a; }

/* ------------------------------------------------------------ confetti */

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 25; /* above the match-over modal, below the toast */
  pointer-events: none;
}

/* --------------------------------------------------------- responsive */

@media (min-width: 880px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr) 330px;
    align-items: start;
  }
  .board { width: min(100%, calc(100vh - 110px)); }
  .panel { position: sticky; top: 66px; }
  .hand { flex-wrap: wrap; overflow: visible; }
}

@media (max-width: 560px) {
  .menu-grid { grid-template-columns: 1fr; }
  .settings-grid, .settings--lobby .settings-grid { grid-template-columns: 1fr; }
  .segs { display: flex; }
  .seg { padding: 0 6px; }
  .menu-card { padding: 22px 16px 18px; }
  .game-layout { padding: 8px; gap: 8px; }
  .board { width: min(100%, calc(100vh - 330px)); min-width: 0; gap: 2px; padding: 4px; }
  .hand-card { width: 48px; height: 68px; font-size: 1rem; }
  .status { font-size: 0.85rem; }
}

@media (prefers-reduced-motion: reduce) {
  .button, .cell, .hand-card, .toast { transition: none; }
  .cell.is-legal:not(.has-chip), .cell.has-chip.is-last::after { animation: none; }
}
