*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0e1c2e;
  --surface: #142338;
  --card: #1d3461;
  --accent: #c0392b;
  --accent2: #c9922a;
  --gold: #c9922a;
  --text: #f0ead6;
  --muted: #8a9bb5;
  --success: #4caf50;
  --warn: #e67e22;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,0.5);
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Layout ── */
.container { width: 100%; max-width: 900px; padding: 24px 16px; }

header {
  width: 100%;
  background: var(--surface);
  border-bottom: 2px solid var(--gold);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-logo img {
  height: 44px;
  width: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--gold);
}
.header-logo h1 { font-size: 1.3rem; color: var(--gold); letter-spacing: 1px; }
header span { color: var(--muted); font-size: .9rem; }

.logo-hero {
  display: block;
  margin: 0 auto 20px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--gold);
  box-shadow: 0 0 24px rgba(201,146,42,.35);
}

/* ── Buttons ── */
button, .btn {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: .95rem;
  font-weight: 600;
  transition: opacity .15s, transform .1s;
}
button:disabled, .btn:disabled { opacity: .35; cursor: not-allowed; }
button:not(:disabled):hover { opacity: .85; transform: translateY(-1px); }
button:not(:disabled):active { transform: translateY(0); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warn    { background: var(--warn); color: #000; }
.btn-muted   { background: var(--card); color: var(--text); }
.btn-sm      { padding: 6px 12px; font-size: .82rem; }

/* ── Forms ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.form-group { margin-bottom: 16px; }
label { display: block; margin-bottom: 6px; font-size: .85rem; color: var(--muted); }
input[type=text], input[type=password], input[type=number], select {
  width: 100%;
  background: var(--card);
  border: 1px solid #2a3a5e;
  border-radius: 6px;
  color: var(--text);
  padding: 10px 14px;
  font-size: .95rem;
  outline: none;
  transition: border-color .2s;
}
input:focus, select:focus { border-color: var(--accent); }
.error { color: var(--accent); font-size: .85rem; margin-top: 8px; }
.info  { color: var(--muted); font-size: .85rem; margin-top: 8px; }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; margin-bottom: 24px; }
.tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
  transition: background .2s, color .2s;
}
.tab.active { background: var(--accent); color: #fff; }

/* ── Lobby ── */
.game-list { display: flex; flex-direction: column; gap: 12px; }

.game-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--card);
  transition: border-color .2s;
}
.game-card:hover { border-left-color: var(--accent); }
.game-card.your-turn {
  border-left-color: var(--gold);
  background: linear-gradient(90deg, rgba(201,146,42,.08) 0%, var(--surface) 60%);
  animation: pulse-border 1.8s ease-in-out infinite;
}
@keyframes pulse-border {
  0%, 100% { border-left-color: var(--gold); }
  50%       { border-left-color: #f0c060; }
}
.your-turn-badge {
  font-size: .78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--gold);
  color: #0e1c2e;
  letter-spacing: .4px;
  white-space: nowrap;
  animation: pulse-badge 1.8s ease-in-out infinite;
}
@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50%       { opacity: .65; }
}
.game-card .meta { flex: 1; }
.game-card .meta h3 { font-size: 1rem; margin-bottom: 4px; }
.game-card .meta p  { font-size: .82rem; color: var(--muted); }
.status-badge {
  font-size: .75rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  letter-spacing: .5px;
  text-transform: uppercase;
}
.status-waiting    { background: var(--card); color: var(--muted); }
.status-inprogress { background: #1a5276; color: #5dade2; }
.status-finalround { background: #7d3c98; color: #d7bde2; }
.status-completed  { background: #1e8449; color: #a9dfbf; }

/* ── Create game modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal { width: 100%; max-width: 480px; }

/* ── Game screen ── */
.game-layout { display: grid; grid-template-columns: 1fr 260px; gap: 20px; align-items: start; }
@media (max-width: 700px) { .game-layout { grid-template-columns: 1fr; } }

.scoreboard {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.scoreboard h2 { padding: 14px 16px; background: var(--card); font-size: 1rem; }
.player-row {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--card);
  gap: 10px;
  transition: background .2s;
}
.player-row.current-turn { background: rgba(233,69,96,.1); }
.player-row .player-name { flex: 1; font-weight: 600; }
.player-row .player-score { font-size: 1.1rem; color: var(--accent2); font-weight: 700; }
.turn-arrow { color: var(--accent); font-size: 1rem; }
.on-board-badge {
  font-size: .7rem;
  background: var(--success);
  color: #000;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 700;
}

.play-area { display: flex; flex-direction: column; gap: 16px; }

.turn-info {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}
.turn-info h2 { font-size: 1rem; color: var(--muted); margin-bottom: 6px; }
.turn-score { font-size: 2rem; font-weight: 700; color: var(--accent2); }
.turn-meta  { font-size: .85rem; color: var(--muted); margin-top: 4px; }

/* ── Dice ── */
.dice-area {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.dice-section-label {
  font-size: .78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
}
.dice-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; min-height: 60px; }

.die {
  width: 58px; height: 58px;
  border-radius: 10px;
  background: var(--card);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  border: 2px solid transparent;
  transition: border-color .15s, background .15s, transform .15s;
  user-select: none;
}
.die.kept-die  { background: #1a4a1a; border-color: var(--success); color: var(--success); }
.die.selectable { cursor: pointer; }
.die.selectable:hover { border-color: var(--accent2); transform: translateY(-3px); }
.die.selected  { border-color: var(--accent2); background: #3d2e0a; color: var(--accent2); transform: translateY(-3px); }

@keyframes spin-shake {
  0%   { transform: rotate(0deg)   scale(1); }
  20%  { transform: rotate(-15deg) scale(1.1); }
  40%  { transform: rotate(15deg)  scale(1.1); }
  60%  { transform: rotate(-10deg) scale(1.05); }
  80%  { transform: rotate(10deg)  scale(1.05); }
  100% { transform: rotate(0deg)   scale(1); }
}
.die.rolling { animation: spin-shake 0.6s ease; }

/* ── Action buttons ── */
.action-row { display: flex; gap: 10px; flex-wrap: wrap; }
.action-row button { flex: 1; min-width: 100px; }

/* ── Status messages ── */
.farkle-banner {
  background: var(--accent);
  color: #fff;
  text-align: center;
  padding: 12px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 1.1rem;
  animation: flash .4s ease 2;
}
@keyframes flash { 0%,100% { opacity:1; } 50% { opacity:.4; } }

.winner-banner {
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  color: #fff;
  text-align: center;
  padding: 24px;
  border-radius: var(--radius);
  font-size: 1.4rem;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.hot-dice-banner {
  background: #7d3c98;
  color: #e8daef;
  text-align: center;
  padding: 10px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: .95rem;
}

/* ── Tag input ── */
.tag-input-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 7px 10px;
  background: var(--card);
  border: 1px solid #2a3a5e;
  border-radius: 6px;
  min-height: 46px;
  cursor: text;
  transition: border-color .2s;
  align-items: center;
}
.tag-input-wrap:focus-within { border-color: var(--accent); }
.tag-input-wrap input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: .9rem;
  padding: 3px 4px;
  min-width: 130px;
  flex: 1;
}
.player-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.player-tag.valid    { background: #1a4a1a; color: var(--success); border-color: var(--success); }
.player-tag.invalid  { background: #4a1a1a; color: var(--accent);  border-color: var(--accent); }
.player-tag.checking { background: #1c1c3a; color: var(--muted);   border-color: #2a3a5e; }
.tag-remove { cursor: pointer; opacity: .6; font-size: 1rem; line-height: 1; margin-left: 2px; }
.tag-remove:hover { opacity: 1; }
kbd {
  background: #2a3a5e;
  border: 1px solid #3a4a6e;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: .78rem;
  font-family: inherit;
}

/* ── Utility ── */
.hidden { display: none !important; }
.mt-16  { margin-top: 16px; }
.text-center { text-align: center; }
