/* ===== Variables ===== */
:root {
    --bg: #faf6f0;
    --surface: #ffffff;
    --ink: #1a1a2e;
    --primary: #ff6b6b;
    --accent: #4ecdc4;
    --muted: #8d8d9c;
    --border: #e8e3dc;
    --success: #7fb069;
    --warning: #f4a261;
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

/* ===== Reset ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: var(--font-ui);
    font-size: 1rem;
    background: var(--bg);
    color: var(--ink);
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font: inherit; }

/* ===== Screens ===== */
.screen { display: none; min-height: 100vh; padding: var(--space-md); }
.screen.is-active { display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ===== Buttons ===== */
.btn {
    min-height: 48px;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    transition: transform 0.1s, background 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:not(:disabled):hover { background: #e85454; }
.btn-secondary {
    background: var(--surface);
    color: var(--ink);
    border: 2px solid var(--border);
}
.btn-secondary.is-active { border-color: var(--primary); color: var(--primary); }
.btn-full { width: 100%; }
.btn-link {
    color: var(--muted);
    padding: var(--space-sm);
    font-weight: 500;
}

/* ===== Landing ===== */
#screen-landing { justify-content: center; align-items: center; }
.landing-card {
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    text-align: center;
}
.landing-title { font-size: 2.5rem; margin-bottom: var(--space-xs); }
.landing-sub { color: var(--muted); margin-bottom: var(--space-lg); }
.inline-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}
.inline-form input {
    min-height: 48px;
    padding: var(--space-md);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
}
.inline-form input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ===== Toasts ===== */
#toast-container {
    position: fixed;
    top: var(--space-md);
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    pointer-events: none;
}
.toast {
    background: var(--warning);
    color: white;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    font-weight: 500;
    pointer-events: auto;
    max-width: 90vw;
}

/* ===== App header ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: var(--space-md);
}

/* ===== Lobby ===== */
.lobby-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    max-width: 480px;
    width: 100%;
    margin: 0 auto;
}
.room-code-block {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    text-align: center;
}
.room-code-label { font-size: 0.9rem; color: var(--muted); margin-bottom: var(--space-sm); }
.room-code {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    color: var(--primary);
    padding: var(--space-sm);
}
.room-code-hint { font-size: 0.85rem; color: var(--muted); margin-top: var(--space-xs); }
.lobby-section-title { font-size: 1.1rem; }
.player-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}
.player-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
}
.player-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--muted);
}
.player-dot.is-connected { background: var(--success); }
.player-name { flex: 1; font-weight: 600; }
.player-badge { font-size: 0.9rem; color: var(--muted); }
.player-ready { font-size: 1.1rem; color: var(--success); }
.player-ready.not-ready { color: var(--muted); }
.lobby-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}
.lobby-hint {
    text-align: center;
    font-size: 0.95rem;
    color: var(--muted);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg);
    border-radius: var(--radius-sm);
    min-height: 1.4em;
}
.lobby-hint strong {
    color: var(--primary);
    font-weight: 700;
}

/* ===== Caller ===== */
#screen-caller { justify-content: center; align-items: center; }
.caller-card {
    max-width: 420px;
    width: 100%;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    text-align: center;
}
.caller-card h2 { color: var(--primary); }
.caller-card input[type="text"] {
    min-height: 48px;
    padding: var(--space-md);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    text-align: center;
    font-size: 1.1rem;
}
.caller-or { color: var(--muted); font-size: 0.9rem; }
.caller-random-row {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}
.caller-random-row select {
    flex: 1;
    min-height: 48px;
    padding: var(--space-sm) var(--space-md);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
}
.random-suggestion {
    background: var(--bg);
    border: 2px dashed var(--accent);
    border-radius: var(--radius-md);
    padding: var(--space-md);
}
#random-suggestion-text { font-size: 1.4rem; font-weight: 700; margin-bottom: var(--space-sm); }
.caller-wait {
    text-align: center;
    padding: var(--space-xl);
}
.caller-wait .spinner { font-size: 3rem; margin-top: var(--space-md); }
.round-label { font-weight: 700; color: var(--primary); }

/* ===== Round (drawing) ===== */
#screen-round { padding: var(--space-sm); gap: var(--space-sm); }
.round-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-xs) var(--space-sm);
}
.round-timer {
    font-size: 1.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}
.round-timer.is-warning { color: var(--warning); }
.round-timer.is-critical { color: var(--primary); animation: pulse 0.6s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }
.round-prompt {
    text-align: center;
    font-size: 1.8rem;
    font-weight: 700;
    padding: var(--space-sm);
    background: var(--surface);
    border-radius: var(--radius-md);
}
.canvas-wrap {
    flex: 1;
    min-height: 0;
    background: var(--surface);
    border: 3px solid var(--ink);
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}
#draw-canvas {
    display: block;
    /* Width and height are set explicitly in Drawing.resize() to exactly
       match the parent's content box, so the drawable area equals the
       visible outline. Do not use percentage sizing here. */
}
.toolbar {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
    padding: var(--space-xs);
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    flex-wrap: wrap;
    justify-content: center;
}
.toolbar-group {
    display: flex;
    gap: var(--space-xs);
    align-items: center;
}
.toolbar-group + .toolbar-group {
    border-left: 1px solid var(--border);
    padding-left: var(--space-sm);
}
.tool-btn, .size-btn, .color-swatch {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid transparent;
}
.tool-btn { font-size: 1.3rem; background: var(--bg); }
.tool-btn.is-active { border-color: var(--primary); background: white; }
.color-swatch.is-active { border-color: var(--ink); transform: scale(1.08); }
.size-dot { background: var(--ink); border-radius: 50%; display: block; }
.size-dot.small  { width: 6px;  height: 6px; }
.size-dot.medium { width: 12px; height: 12px; }
.size-dot.large  { width: 18px; height: 18px; }
.size-btn.is-active { border-color: var(--primary); }

.mini-status {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    justify-content: center;
    font-size: 0.85rem;
    color: var(--muted);
}
.mini-status .mini-player.submitted { color: var(--success); font-weight: 700; }

/* ===== Reveal ===== */
.reveal-title { font-weight: 700; font-size: 1.2rem; }
.reveal-prompt { color: var(--primary); font-weight: 700; margin-top: var(--space-xs); }
.reveal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: 1fr;
    gap: var(--space-sm);
    flex: 1;
    min-height: 0;
    padding: var(--space-sm) 0;
}
.reveal-cell {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}
.reveal-cell-name {
    font-size: 0.85rem;
    font-weight: 600;
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.reveal-cell canvas {
    flex: 1;
    width: 100%;
    display: block;
}
.reveal-reactions {
    position: absolute;
    bottom: var(--space-sm);
    left: var(--space-sm);
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    max-width: 80%;
    pointer-events: none;
}
.reaction-bar {
    display: flex;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
}
.emoji-btn {
    width: 48px;
    height: 48px;
    font-size: 1.5rem;
    border-radius: var(--radius-sm);
    background: var(--bg);
}
.reveal-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-top: var(--space-sm);
}
.done-block { text-align: center; }
.btn-done.is-done {
    background: var(--success);
    color: white;
    border-color: var(--success);
}
.done-helper { color: var(--muted); font-size: 0.8rem; margin-top: var(--space-xs); }
.reaction-fly {
    position: absolute;
    font-size: 1.5rem;
    pointer-events: none;
    animation: fly 1.2s ease-out forwards;
}
@keyframes fly {
    0% { opacity: 0; transform: translate(0, 20px) scale(0.6); }
    20% { opacity: 1; transform: translate(0, 0) scale(1.2); }
    100% { opacity: 0; transform: translate(0, -40px) scale(1); }
}

/* ===== Gallery ===== */
#screen-gallery { overflow-y: auto; }
.prompt-history {
    padding: var(--space-md);
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
}
.prompt-history-label {
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: var(--space-xs);
}
#prompt-history-list {
    font-weight: 600;
    line-height: 1.5;
}
.gallery-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}
.gallery-card {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.gallery-card-name {
    padding: var(--space-sm) var(--space-md);
    font-weight: 700;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.gallery-card canvas {
    display: block;
    width: 100%;
    aspect-ratio: 3 / 4;
    background: white;
}
.gallery-actions {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
    padding-bottom: var(--space-lg);
}
.gallery-actions .btn { flex: 1; }
