/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { overflow-x: hidden; max-width: 100vw; }


/* ── CSS Variables ──────────────────────────────────────────────────────────── */
:root {
    --bg:     #121213;
    --bg2:    #1a1a1b;
    --bg3:    #242426;
    --border: #3a3a3c;
    --text:   #e8e6e0;
    --muted:  #818384;
    --green:  #538d4e;
    --yellow: #b59f3b;
    --grey:   #3a3a3c;
    --accent: #c8b97a;
    --red:    #c0392b;
    --blue:   #3b82f6;
}

/* ── Body ───────────────────────────────────────────────────────────────────── */
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0;
    /* PWA safe areas — notch top, home bar bottom */
    padding-top:    env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left:   env(safe-area-inset-left, 0px);
    padding-right:  env(safe-area-inset-right, 0px);
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
header {
    width: 100%;
    max-width: 700px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    gap: 10px;
    flex-shrink: 0;
    flex-wrap: nowrap;
    overflow: visible; /* needed for dropdown to show */
    position: relative;
}

.header-left {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}


h1 {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-weight: 900;
    color: var(--text);
    letter-spacing: 3px;
    font-size: 1.5rem;
}

.header-sub {
    font-size: 11px;
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

/* ── Nav links ──────────────────────────────────────────────────────────────── */
.nav-links {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: nowrap;
}

/* ── Hamburger menu (mobile only) ───────────────────────────────────────────── */
.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    padding: 6px 7px;
    flex-shrink: 0;
}
.hamburger span {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: all 0.2s;
}
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.nav-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    gap: 6px;
    flex-direction: column;
    z-index: 200;
    min-width: 160px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.nav-dropdown.open { display: flex; }
.nav-dropdown .nav-link {
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    font-size: 13px;
}


@media (max-width: 600px) {
    .nav-links  { display: none; }
    .hamburger  { display: flex; }
}

.nav-link {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 11px;
    color: var(--muted);
    text-decoration: none;
    border: 1px solid var(--border);
    padding: 5px 12px;
    border-radius: 4px;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    cursor: pointer;
    background: transparent;
}
.nav-link:hover { color: var(--accent); border-color: var(--accent); }

/* ── Screens ────────────────────────────────────────────────────────────────── */
.screen { display: none; width: 100%; max-width: 480px; padding: 16px 12px 24px; flex-direction: column; align-items: center; gap: 12px; }
.screen.active { display: flex; flex: 1; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.card h2 {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 1rem;
    letter-spacing: 2px;
    color: var(--accent);
    text-transform: uppercase;
}
.card p { font-size: 13px; color: var(--muted); line-height: 1.7; }

/* ── Inputs ─────────────────────────────────────────────────────────────────── */
input[type="text"], input[type="email"], select {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    padding: 11px 14px;
    width: 100%;
    outline: none;
    transition: border-color 0.2s;
}
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: var(--muted); }
select option { background: var(--bg2); }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
    padding: 12px 20px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 1px;
    transition: all 0.15s;
    width: 100%;
    text-align: center;
    text-decoration: none;
    display: block;
}
.btn:active   { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-accent { background: var(--accent); color: #121213; }
.btn-green  { background: var(--green);  color: white; }
.btn-yellow { background: var(--yellow); color: white; }
.btn-red    { background: var(--red);    color: white; }
.btn-ghost  { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

/* ── Divider ────────────────────────────────────────────────────────────────── */
.divider {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 12px;
    width: 100%;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Form helpers ───────────────────────────────────────────────────────────── */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size: 11px; color: var(--muted); letter-spacing: 0.05em; }

.error-msg   { color: var(--red); font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; text-align: center; min-height: 16px; }
.success-msg { color: var(--green); font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; text-align: center; min-height: 16px; }

/* ── Game board (shared) ────────────────────────────────────────────────────── */
.game-board {
    display: grid;
    grid-template-columns: repeat(5, 60px);
    gap: 8px;
    justify-content: center;
    margin: 16px auto;
}

.board-wrapper { display: flex; flex-direction: column; gap: 6px; align-items: center; width: 100%; }
.board-row     { display: flex; gap: 6px; }

.tile {
    width: 60px;
    height: 60px;
    border: 2px solid var(--border);
    border-radius: 4px;
    font-size: 28px;
    font-weight: 900;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg3);
    text-transform: uppercase;
    color: var(--text);
    transition: background 0.2s, border-color 0.2s;
}
.tile.active  { border-color: #565758; }
.tile.filled  { border-color: #565758; }
.tile.correct { background: var(--green);  border-color: var(--green);  color: white; }
.tile.present { background: var(--yellow); border-color: var(--yellow); color: white; }
.tile.absent  { background: var(--grey);   border-color: var(--grey);   color: white; }

/* ── Keyboard ───────────────────────────────────────────────────────────────── */
.keyboard { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 500px; margin: 8px auto; padding: 0 6px; user-select: none; }
.kb-row   { display: flex; justify-content: center; gap: 5px; width: 100%; }

.kb-key {
    height: 58px;
    min-width: 0;
    flex: 1;
    max-width: 43px;
    border: none;
    border-radius: 4px;
    background: var(--muted);
    color: white;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.kb-key:active   { transform: scale(0.95); }
.kb-wide         { max-width: 66px; font-size: 11px; }
.kb-key.correct  { background: var(--green); }
.kb-key.present  { background: var(--yellow); }
.kb-key.absent   { background: #3a3a3c; }
.kb-key:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── Message ────────────────────────────────────────────────────────────────── */
.message { font-size: 14px; min-height: 24px; text-align: center; font-weight: 600; }
.message.success { color: var(--green); }
.message.failure { color: var(--red); }

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    background: var(--text);
    color: var(--bg);
    padding: 10px 20px;
    border-radius: 6px;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1px;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 999;
    pointer-events: none;
    max-width: 320px;
    text-align: center;
}
.toast.show  { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red); color: white; }

/* ── Player list (lobby) ────────────────────────────────────────────────────── */
.player-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.player-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg3);
    border-radius: 6px;
    border: 1px solid var(--border);
}
.player-row-name { font-size: 14px; color: var(--text); }
.player-badge {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--accent);
    color: #121213;
    font-weight: 700;
}
.player-badge.guesser { background: var(--bg2); color: var(--muted); border: 1px solid var(--border); }

/* ── Room code ──────────────────────────────────────────────────────────────── */
.room-code-display {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 3rem;
    font-weight: 900;
    letter-spacing: 12px;
    color: var(--accent);
    text-align: center;
    padding: 8px 0;
}

/* ── Daily: leaderboard ─────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 6px; width: 100%; }
.tab-btn {
    flex: 1;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg3);
    color: var(--muted);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s;
}
.tab-btn.active { background: var(--accent); color: #121213; border-color: var(--accent); }

.lb-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg3);
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 13px;
    gap: 8px;
}
.lb-rank  { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-weight: 900; color: var(--accent); width: 28px; flex-shrink: 0; }
.lb-name  { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-stat  { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size: 11px; color: var(--muted); text-align: right; flex-shrink: 0; }
.lb-row.me { border-color: var(--accent); background: rgba(200,185,122,0.08); }
.lb-arrow      { font-size: 10px; margin-left: 4px; }
.lb-arrow.up   { color: var(--green); }
.lb-arrow.down { color: var(--red); }
.lb-arrow.same { color: var(--muted); }
.lb-you { font-size: 10px; color: var(--accent); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; margin-left: 4px; }

/* ── Daily: stats row ───────────────────────────────────────────────────────── */
.stats-row { display: flex; justify-content: space-around; width: 100%; padding: 12px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.stat { text-align: center; }
.stat-num   { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 1.8rem; font-weight: 900; color: var(--accent); }
.stat-label { font-size: 10px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; text-transform: uppercase; letter-spacing: 0.05em; }

/* ── Daily: result grid ─────────────────────────────────────────────────────── */
.result-summary { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.result-emoji   { font-size: 3rem; }
.result-title   { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 1.4rem; font-weight: 900; letter-spacing: 2px; }
.result-grid     { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.result-grid-row { display: flex; gap: 4px; }
.result-grid-tile {
    width: 28px; height: 28px; border-radius: 3px;
    display: flex; align-items: center; justify-content: center; font-size: 16px;
}

/* ── Solo: how to play modal ────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 100; padding: 20px;
    opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
    background: var(--bg2); border-radius: 12px;
    padding: 32px 28px 28px; max-width: 380px; width: 100%;
    position: relative; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    border: 1px solid var(--border);
    transform: translateY(12px); transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-close {
    position: absolute; top: 14px; right: 16px;
    background: none; border: none; font-size: 22px;
    cursor: pointer; color: var(--muted); line-height: 1;
    padding: 2px 6px; border-radius: 4px; transition: color 0.15s, background 0.15s;
}
.modal-close:hover { color: var(--text); background: var(--bg3); }
.modal h2 {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-weight: 900;
    font-size: 1.3rem; letter-spacing: 2px; color: var(--accent);
    margin-bottom: 18px; text-align: center;
}
.modal p { font-size: 14px; color: var(--text); line-height: 1.6; margin-bottom: 18px; text-align: left; }
.modal-divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.example { margin-bottom: 18px; text-align: left; }
.example-tiles { display: flex; gap: 5px; margin-bottom: 8px; }
.ex-tile {
    width: 44px; height: 44px; border: 2px solid var(--border); border-radius: 4px;
    font-size: 20px; font-weight: 900; font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    display: flex; align-items: center; justify-content: center;
    text-transform: uppercase; color: var(--text); background: var(--bg3);
}
.ex-tile.correct { background: var(--green);  border-color: var(--green);  color: white; }
.ex-tile.present { background: var(--yellow); border-color: var(--yellow); color: white; }
.ex-tile.absent  { background: var(--grey);   border-color: var(--grey);   color: white; }
.example p { font-size: 13px; color: var(--text); margin: 0; }
.example p strong { color: var(--accent); }

/* ── Solo: buttons container ────────────────────────────────────────────────── */
.buttons-container {
    display: flex; flex-wrap: wrap; gap: 12px;
    justify-content: center; align-items: center; margin-top: 24px;
}
.btn-new-game  { background: #5b9bd5; color: white; }
.btn-new-game:hover { background: #4a7fb8; }

/* ── Shared: share result (solo mode) ───────────────────────────────────────── */
.share-container { display: none; justify-content: center; margin-top: 4px; margin-bottom: 8px; }
.share-container .reset-btn {
    background: var(--accent); color: var(--bg); font-weight: 700;
    transition: opacity 0.2s, transform 0.1s, background-color 0.2s;
}
.share-container .reset-btn:hover  { background: #d4c68a; }
.share-container .reset-btn:active { transform: scale(0.97); }

/* ── Animations ─────────────────────────────────────────────────────────────── */
@keyframes shake {
    0%,100% { transform: translateX(0); } 20% { transform: translateX(-6px); }
    40%  { transform: translateX(6px); } 60%  { transform: translateX(-4px); }
    80%  { transform: translateX(4px); }
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .tile { width: 52px; height: 52px; font-size: 22px; }
    .game-board { grid-template-columns: repeat(5, 52px); gap: 6px; }
    .kb-key  { height: 50px; max-width: 36px; font-size: 12px; }
    .kb-wide { max-width: 56px; font-size: 10px; }
    .keyboard { padding: 0 4px; gap: 6px; }
    .kb-row  { gap: 4px; }
}
@media (max-width: 380px) {
    .tile { width: 44px; height: 44px; font-size: 18px; }
    .game-board { grid-template-columns: repeat(5, 44px); gap: 5px; }
    .kb-key  { height: 44px; max-width: 30px; font-size: 11px; }
    .kb-wide { max-width: 48px; font-size: 10px; }
}