@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800;900&family=Lora:ital,wght@0,400;0,600;1,400&display=swap');

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

:root {
  --bg: #FAF8F5;
  --surface: #F2EFE9;
  --surface2: #E5E1D8;
  --accent: #1D3461;
  --accent-hover: #162849;
  --accent2: #3A5F9F;
  --text: #1C1C1E;
  --text-muted: #6B6867;
  --board-bg: #4a7c59;
  --cell-size: 38px;
  --tw: #b5341f;
  --dw: #d4752a;
  --tl: #2471a3;
  --dl: #1e8449;
  --ct: #b5341f;
  --tile-bg: #F5E6C8;
  --tile-text: #2c2c2c;
}

body {
  font-family: 'Lora', Georgia, serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 1rem;
  line-height: 1.6;
}

h1, h2, h3, h4, h5, h6,
.nav-brand, .btn-primary, .btn-secondary, .btn-danger,
.badge, .rack-label, .sidebar-section h3,
.dashboard-header, .game-id, .player-score,
.move-player, .move-score {
  font-family: 'Inter', system-ui, sans-serif;
}

/* Navbar */
.navbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--accent);
  border-bottom: none;
}
.nav-brand {
  font-size: 1.3rem; font-weight: 800; color: #fff;
  text-decoration: none; letter-spacing: -0.5px;
}
.nav-links { display: flex; align-items: center; gap: 1.25rem; }
.nav-links a { color: rgba(255,255,255,0.85); text-decoration: none; font-size: 0.875rem; font-family: 'Inter', sans-serif; }
.nav-links a:hover { color: #fff; }
.nav-user { color: rgba(255,255,255,0.6); font-size: 0.85rem; font-family: 'Inter', sans-serif; }
.navbar .btn-primary { background: #fff; color: var(--accent); }
.navbar .btn-primary:hover { background: rgba(255,255,255,0.9); }

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger {
  display: inline-block; padding: 0.55rem 1.25rem; border-radius: 6px;
  border: none; cursor: pointer; font-size: 0.875rem; font-weight: 600;
  text-decoration: none; transition: background 0.15s, opacity 0.15s;
  font-family: 'Inter', sans-serif;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid #ccc8bf; }
.btn-secondary:hover:not(:disabled) { background: #d9d5cc; }
.btn-danger { background: #fff0ee; color: #9b1c1c; border: 1px solid #f5c6c6; }
.btn-danger:hover { background: #fee2e2; }
.btn-primary:disabled, .btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-large { padding: 0.8rem 2rem; font-size: 1rem; }

/* Auth forms */
.auth-form {
  max-width: 420px; margin: 3rem auto; padding: 2rem 2.5rem;
  background: #fff; border-radius: 12px;
  border: 1px solid var(--surface2);
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.auth-form h1 { margin-bottom: 1.5rem; font-size: 1.6rem; }
.auth-form h2 { margin-bottom: 1rem; font-size: 1.1rem; }
.auth-form label {
  display: flex; flex-direction: column; gap: 0.35rem;
  margin-bottom: 1rem; font-size: 0.875rem; color: var(--text-muted);
  font-family: 'Inter', sans-serif;
}
.auth-form input[type="text"],
.auth-form input[type="email"],
.auth-form input[type="password"],
.auth-form input[type="date"] {
  padding: 0.6rem 0.8rem; border-radius: 6px;
  border: 1px solid var(--surface2); background: var(--bg);
  color: var(--text); font-size: 1rem; font-family: 'Lora', serif;
}
.auth-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.auth-form button { width: 100%; margin-top: 0.5rem; }
.auth-form p { margin-top: 1rem; font-size: 0.875rem; color: var(--text-muted); }
.auth-form a { color: var(--accent); }
.checkbox-label {
  display: flex !important; flex-direction: row !important; align-items: center;
  gap: 0.6rem !important; font-size: 0.95rem !important; color: var(--text) !important;
  cursor: pointer;
}
.error { color: #9b1c1c; background: #fff0ee; border: 1px solid #f5c6c6; padding: 0.6rem 0.8rem; border-radius: 6px; font-size: 0.875rem; margin-bottom: 1rem; font-family: 'Inter', sans-serif; }
.success { color: #14532d; background: #f0fdf4; border: 1px solid #bbf7d0; padding: 0.6rem 0.8rem; border-radius: 6px; font-size: 0.875rem; margin-bottom: 1rem; font-family: 'Inter', sans-serif; }

/* Hero */
.hero { max-width: 640px; margin: 4rem auto; padding: 0 1.5rem; text-align: center; }
.hero h1 { font-size: 3.5rem; font-weight: 900; color: var(--accent); margin-bottom: 0.5rem; letter-spacing: -1px; font-family: 'Inter', sans-serif; }
.hero .tagline { font-size: 1.15rem; color: var(--text-muted); margin-bottom: 2rem; font-style: italic; }
.how-to-play {
  background: #fff; border-radius: 12px; padding: 1.5rem 2rem;
  text-align: left; margin-bottom: 2rem;
  border: 1px solid var(--surface2);
}
.how-to-play h2 {
  margin-bottom: 1rem; font-size: 0.75rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1.5px; font-family: 'Inter', sans-serif;
}
.how-to-play ul { padding-left: 1.2rem; display: flex; flex-direction: column; gap: 0.6rem; line-height: 1.6; font-size: 0.875rem; }
.hero-actions { display: flex; gap: 1rem; justify-content: center; }

/* Dashboard */
.dashboard { max-width: 700px; margin: 2rem auto; padding: 0 1rem; }
.dashboard-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.dashboard-header h1 { font-size: 1.5rem; font-weight: 800; }
.game-card {
  display: flex; justify-content: space-between; align-items: center;
  background: #fff; border-radius: 10px; padding: 1rem 1.25rem;
  margin-bottom: 0.75rem; text-decoration: none; color: var(--text);
  border: 1px solid var(--surface2); transition: border-color 0.15s, box-shadow 0.15s;
}
.game-card:hover { border-color: var(--accent2); box-shadow: 0 2px 8px rgba(0,0,0,0.07); }
.game-card--my-turn { border-color: var(--accent); border-width: 2px; }
.game-card-info { display: flex; flex-direction: column; gap: 0.2rem; }
.game-id { font-weight: 700; font-family: 'Inter', sans-serif; }
.game-creator, .game-players { font-size: 0.85rem; color: var(--text-muted); font-family: 'Inter', sans-serif; }
.game-card-right { display: flex; flex-direction: column; align-items: flex-end; gap: 0.3rem; }
.game-status { font-size: 0.85rem; color: var(--text-muted); font-family: 'Inter', sans-serif; }
.game-score { font-weight: 600; font-family: 'Inter', sans-serif; }
.game-badges { display: flex; gap: 0.4rem; }
.empty-state { color: var(--text-muted); text-align: center; margin-top: 3rem; font-style: italic; }

/* Badges */
.badge { font-size: 0.7rem; font-weight: 700; padding: 0.2rem 0.5rem; border-radius: 4px; text-transform: uppercase; letter-spacing: 0.5px; font-family: 'Inter', sans-serif; }
.badge-turn { background: var(--accent); color: #fff; }
.badge-vote { background: #92400e; color: #fef3c7; }
.badge-resigned { background: var(--surface2); color: var(--text-muted); }

/* Game layout */
.game-layout { display: flex; gap: 1rem; padding: 1rem; align-items: flex-start; }
.board-area { flex: 0 0 auto; }
.sidebar { flex: 0 0 280px; display: flex; flex-direction: column; gap: 0.75rem; }

/* Board */
.board {
  display: grid;
  grid-template-columns: repeat(15, var(--cell-size));
  grid-template-rows: repeat(15, var(--cell-size));
  gap: 2px;
  background: var(--board-bg);
  padding: 6px;
  border-radius: 8px;
  border: 3px solid #36614a;
  user-select: none;
}
.cell {
  width: var(--cell-size); height: var(--cell-size);
  display: flex; align-items: center; justify-content: center;
  border-radius: 3px; font-size: 0.6rem; font-weight: 700;
  cursor: pointer; position: relative; transition: filter 0.1s;
  text-transform: uppercase; letter-spacing: 0;
  background: #5a9068;
  font-family: 'Inter', sans-serif;
}
.cell:hover { filter: brightness(1.15); }
.cell.TW { background: var(--tw); color: #fff; }
.cell.DW { background: var(--dw); color: #fff; }
.cell.TL { background: var(--tl); color: #fff; }
.cell.DL { background: var(--dl); color: #fff; }
.cell.CT { background: var(--ct); color: #fff; }
.cell.CT::before { content: '★'; font-size: 1rem; }
.cell.has-tile { background: var(--tile-bg) !important; cursor: default; }
.cell.has-tile .cell-label { display: none; }
.cell.pending-tile { background: #fde68a !important; cursor: pointer; }
.cell.drop-target { filter: brightness(1.3); outline: 2px dashed var(--accent); }

/* Tile on board */
.tile-on-board {
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--tile-bg); border-radius: 3px;
  color: var(--tile-text); font-weight: 800; font-size: 1rem;
  position: relative; font-family: 'Inter', sans-serif;
}
.tile-on-board .tile-value { position: absolute; bottom: 1px; right: 3px; font-size: 0.55rem; font-weight: 600; }
.tile-on-board.blank { color: #888; }

/* Rack */
.rack-area { margin-top: 0.75rem; }
.rack-label { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 1px; font-family: 'Inter', sans-serif; }
.rack { display: flex; gap: 4px; flex-wrap: wrap; min-height: calc(var(--cell-size) + 4px); }
.rack-tile {
  width: var(--cell-size); height: var(--cell-size);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--tile-bg); border-radius: 5px; border: 2px solid #c9a96e;
  color: var(--tile-text); font-weight: 800; font-size: 1rem;
  cursor: pointer; position: relative; transition: transform 0.1s, box-shadow 0.1s;
  font-family: 'Inter', sans-serif;
}
.rack-tile:hover { transform: translateY(-3px); box-shadow: 0 4px 8px rgba(0,0,0,0.15); }
.rack-tile.selected { border-color: var(--accent); transform: translateY(-5px); box-shadow: 0 6px 12px rgba(29,52,97,0.25); }
.rack-tile .tile-value { position: absolute; bottom: 1px; right: 3px; font-size: 0.55rem; font-weight: 600; }
.rack-tile.blank-tile { color: #888; border-style: dashed; }
.rack-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }
.move-error { font-family: 'Inter', sans-serif; }

/* Sidebar sections */
.sidebar-section { background: #fff; border-radius: 10px; padding: 1rem; border: 1px solid var(--surface2); }
.sidebar-section h3 { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text-muted); margin-bottom: 0.75rem; font-family: 'Inter', sans-serif; }
.player-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0; border-bottom: 1px solid var(--surface2); font-size: 0.875rem; font-family: 'Inter', sans-serif; }
.player-row:last-child { border-bottom: none; }
.player-row--active .player-name { color: var(--accent); font-weight: 700; }
.player-row--resigned { opacity: 0.45; }
.player-name { flex: 1; }
.player-score { font-weight: 700; }
.turn-arrow { color: var(--accent); }
.status-tag { display: inline-block; font-size: 0.8rem; font-weight: 600; padding: 0.2rem 0.6rem; border-radius: 4px; margin-bottom: 0.5rem; font-family: 'Inter', sans-serif; }
.status-waiting { background: var(--surface); color: var(--text-muted); border: 1px solid var(--surface2); }
.status-finished { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.invite-note { font-size: 0.8rem; color: var(--text-muted); font-family: 'Inter', sans-serif; }

/* Move history */
.move-row { display: flex; align-items: baseline; gap: 0.5rem; padding: 0.35rem 0; border-bottom: 1px solid var(--surface2); font-size: 0.85rem; }
.move-row:last-child { border-bottom: none; }
.move-player { font-weight: 700; flex-shrink: 0; font-family: 'Inter', sans-serif; }
.move-words { flex: 1; color: var(--text-muted); font-style: italic; }
.move-score { font-weight: 700; color: #15803d; flex-shrink: 0; font-family: 'Inter', sans-serif; }
.move-score--pending { color: #b45309; }
.waiting-msg { color: var(--text-muted); font-style: italic; padding: 0.5rem 0; }

/* Voting */
.vote-card { background: var(--surface); border-radius: 8px; padding: 0.75rem; margin-bottom: 0.5rem; border: 1px solid var(--surface2); }
.vote-words { font-weight: 700; font-size: 1rem; margin-bottom: 0.2rem; font-family: 'Inter', sans-serif; }
.vote-by { font-size: 0.8rem; color: var(--text-muted); font-family: 'Inter', sans-serif; }
.vote-deadline { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.5rem; font-family: 'Inter', sans-serif; }
.vote-stars { display: flex; gap: 3px; flex-wrap: wrap; }
.vote-btn { width: 26px; height: 26px; border-radius: 4px; border: 1px solid var(--surface2); background: #fff; color: var(--text); font-size: 0.8rem; cursor: pointer; font-weight: 600; transition: background 0.1s; font-family: 'Inter', sans-serif; }
.vote-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.vote-confirm { color: #15803d; font-weight: 600; font-size: 0.9rem; font-family: 'Inter', sans-serif; }

/* Blank tile modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box { background: #fff; border-radius: 12px; padding: 1.5rem; max-width: 360px; width: 90%; border: 1px solid var(--surface2); box-shadow: 0 8px 32px rgba(0,0,0,0.12); }
.modal-box h3 { margin-bottom: 1rem; font-family: 'Inter', sans-serif; }
.blank-letters { display: flex; flex-wrap: wrap; gap: 6px; }
.blank-btn { width: 36px; height: 36px; border-radius: 5px; border: 1px solid var(--surface2); background: var(--bg); color: var(--text); font-weight: 700; cursor: pointer; font-size: 0.95rem; font-family: 'Inter', sans-serif; }
.blank-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

@media (max-width: 900px) {
  :root { --cell-size: 28px; }
  .game-layout { flex-direction: column; }
  .sidebar { flex: none; width: 100%; }
}
