/* =====================
   TheStoryGame — Base Styles
   ===================== */

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

:root {
    --bg:         #0f1117;
    --surface:    #1a1d27;
    --surface2:   #232635;
    --border:     #2e3248;
    --accent:     #7c6af7;
    --accent-dim: #4e4599;
    --text:       #e8e8f0;
    --text-muted: #8888aa;
    --success:    #3ecf8e;
    --error:      #f87171;
    --radius:     10px;
    --font:       'Segoe UI', system-ui, sans-serif;
}

/* ---- Light mode ---- */
/* html.light has specificity (0,1,0,1) — beats :root (0,1,0,0) cleanly */
html.light {
    --bg:         #f4f5fb;
    --surface:    #ffffff;
    --surface2:   #eef0f8;
    --border:     #d4d6e8;
    --accent:     #5b4dd6;
    --accent-dim: #4035a0;
    --text:       #1c1d2e;
    --text-muted: #62647e;
    --success:    #1a7a50;
    --error:      #c0392b;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    min-height: 100vh;
    line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Auth pages ---- */
.auth-container {
    max-width: 420px;
    margin: 80px auto;
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.auth-container h1 {
    font-size: 1.6rem;
    color: var(--accent);
    margin-bottom: 0.25rem;
}

.auth-container h2 {
    font-size: 1.1rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-bottom: 1.5rem;
}

.auth-container form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

label .hint { font-size: 0.8rem; color: var(--text-muted); }

input[type="text"],
input[type="email"],
input[type="password"] {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 0.6rem 0.75rem;
    font-size: 1rem;
    width: 100%;
    transition: border-color 0.2s;
}

input:focus {
    outline: none;
    border-color: var(--accent);
}

button[type="submit"],
.btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.7rem 1.25rem;
    font-size: 1rem;
    cursor: pointer;
    margin-top: 0.5rem;
    transition: background 0.2s;
}

button[type="submit"]:hover,
.btn:hover { background: var(--accent-dim); }

.btn-outline {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
}

.btn-outline:hover { background: var(--accent); color: #fff; }

.auth-link {
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    text-align: center;
}

/* ---- Alerts ---- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.alert-error   { background: #3b1a1a; border: 1px solid var(--error);   color: var(--error); }
.alert-success { background: #0f2e22; border: 1px solid var(--success); color: var(--success); }

/* ---- Layout ---- */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.site-header .logo { font-size: 1.3rem; color: var(--accent); font-weight: 700; }

.site-nav { display: flex; gap: 1.5rem; align-items: center; font-size: 0.95rem; }

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.2rem 0.45rem;
    line-height: 1;
    margin-top: 0;
    transition: border-color 0.2s, background 0.2s;
}
.theme-toggle:hover {
    border-color: var(--accent);
    background: var(--surface2);
    color: var(--text);
}

.main-content {
    max-width: 1100px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

/* ---- Cards ---- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.card-title   { font-size: 1.1rem; font-weight: 600; }
.card-meta    { font-size: 0.82rem; color: var(--text-muted); }
.card-rules   { font-size: 0.85rem; color: var(--text-muted); border-top: 1px solid var(--border); padding-top: 0.5rem; margin-top: 0.25rem; }

.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-active  { background: #1a3a2a; color: var(--success); }
.badge-waiting { background: #2a2a1a; color: #d4a017; }
.badge-ended   { background: #2a1a2a; color: #a07ad4; }

/* ---- Forms (story create etc.) ---- */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-section {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    border-top: 1px solid var(--border);
    padding-top: 1.1rem;
}

.form-section:first-child { border-top: none; padding-top: 0; }

.form-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

textarea {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 0.6rem 0.75rem;
    font-size: 1rem;
    font-family: var(--font);
    width: 100%;
    resize: vertical;
    transition: border-color 0.2s;
}

textarea:focus { outline: none; border-color: var(--accent); }

select {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 0.6rem 0.75rem;
    font-size: 1rem;
    width: 100%;
    cursor: pointer;
    transition: border-color 0.2s;
}

select:focus { outline: none; border-color: var(--accent); }

input[type="number"] {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 0.6rem 0.75rem;
    font-size: 1rem;
    width: 100%;
    transition: border-color 0.2s;
}

input[type="number"]:focus { outline: none; border-color: var(--accent); }

/* ---- Invite Code Display ---- */
.invite-code-box {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    background: var(--surface2);
    border: 1px dashed var(--accent);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-top: 0.25rem;
}

.invite-label { font-size: 0.75rem; color: var(--text-muted); }

.invite-code {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.25em;
    color: var(--accent);
    font-family: 'Courier New', monospace;
}

/* ---- Story Write Page ---- */
.story-header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.story-title-row {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.story-title  { font-size: 1.4rem; font-weight: 700; }
.title-locked { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.story-meta   { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.25rem; }

.rules-panel {
    font-size: 0.83rem;
    color: var(--text-muted);
    background: var(--surface2);
    border-radius: 6px;
    padding: 0.75rem 1rem;
    line-height: 1.6;
}

.rules-list {
    margin: 0.3rem 0 0 1.2rem;
    padding: 0;
}

.entry-scroll {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    margin-bottom: 1.75rem;
}

.entry {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}

.entry-mine   { border-left: 3px solid var(--accent); }
.entry-theirs { border-left: 3px solid var(--success); }

.entry-author  { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.4rem; }
.entry-content { font-size: 1rem; line-height: 1.75; white-space: pre-wrap; }
.entry-footer  { display: flex; justify-content: space-between; align-items: center; margin-top: 0.5rem; }
.entry-time    { font-size: 0.75rem; color: var(--text-muted); }
.entry-edit-btn {
    font-size: 0.75rem;
    color: var(--accent);
    text-decoration: none;
    padding: 0.2rem 0.5rem;
    border: 1px solid var(--accent);
    border-radius: 4px;
    transition: background 0.2s;
}
.entry-edit-btn:hover { background: var(--accent); color: #fff; text-decoration: none; }

.entry-system {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
    padding: 0.5rem 0;
}

.write-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
    width: 100%;
}

.write-form label {
    width: 100%;
}

.write-form textarea {
    width: 100%;
    min-height: 260px;
    font-size: 1rem;
    line-height: 1.7;
    resize: vertical;
    display: block;
}

.write-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.char-counter          { font-size: 0.85rem; color: var(--text-muted); }
.char-counter.char-limit-warn { color: #d4a017; }
.char-counter.char-limit-hit  { color: var(--error); font-weight: 600; }

.waiting-box {
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.waiting-box h3 { font-size: 1.15rem; }
.waiting-box p  { font-size: 0.9rem; color: var(--text-muted); }

.story-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.btn-sm { font-size: 0.82rem; padding: 0.4rem 0.85rem; }
.btn-danger { border-color: var(--error); color: var(--error); }
.btn-danger:hover { background: var(--error); color: #fff; }
.btn-danger-solid { background: var(--error); color: #fff; border: none; }
.btn-danger-solid:hover { background: #c0392b; }

/* ---- Confirm / action pages ---- */
.confirm-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.85rem;
    text-align: center;
}
.confirm-box h2 { font-size: 1.4rem; }
.confirm-box p  { font-size: 0.95rem; color: var(--text-muted); max-width: 400px; }

/* ---- Emoji Reactions ---- */
.reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.75rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border);
}

.react-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.25rem 0.6rem;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    color: var(--text);
    line-height: 1;
}

.react-btn:hover {
    background: var(--surface);
    border-color: var(--accent);
}

.react-btn.reacted {
    transform: scale(1.25);
}

.react-count {
    font-size: 0.78rem;
    color: var(--text-muted);
    min-width: 0.6rem;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    /* Header */
    .site-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.6rem;
        padding: 0.75rem 1rem;
    }
    .site-nav {
        flex-wrap: wrap;
        gap: 0.75rem;
        font-size: 0.88rem;
    }

    /* Main content padding */
    .main-content { padding: 0 1rem; }

    /* Auth */
    .auth-container { margin: 1.5rem 1rem; padding: 1.5rem; }

    /* Story write page */
    .write-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 0.6rem;
    }
    .write-footer .char-counter { text-align: center; }
    .story-actions { flex-direction: column; }
    .story-actions .btn,
    .story-actions button { width: 100%; text-align: center; }

    /* Story header */
    .story-title-row { flex-direction: column; gap: 0.35rem; }
    .story-header { padding: 1rem; }

    /* Waiting box */
    .waiting-box { padding: 1.5rem 1rem; }

    /* Confirm box */
    .confirm-box { padding: 1.75rem 1rem; }

    /* Form cards */
    .form-card { padding: 1.25rem 1rem; }

    /* Card grid: single column on small screens */
    .card-grid { grid-template-columns: 1fr; }

    /* Invite code */
    .invite-code { font-size: 1.25rem; }

    /* Reactions: smaller tap targets are fine, allow more per row */
    .react-btn { font-size: 0.95rem; padding: 0.2rem 0.5rem; }
}

@media (max-width: 480px) {
    .site-header { padding: 0.6rem 0.75rem; }
    .site-header .logo { font-size: 1.1rem; }
    .site-nav { gap: 0.5rem; font-size: 0.83rem; }

    /* Full-width buttons on tiny screens */
    .btn { display: block; width: 100%; text-align: center; }
    .btn-sm { display: inline-flex; width: auto; }   /* keep small btns inline */
    .btn-outline { display: inline-flex; width: auto; } /* keep outline btns natural width unless in actions */

    .story-actions .btn,
    .story-actions .btn-outline { display: block; width: 100%; }
}
