/* Quiz editor. Same printed-programme look as the home page (see CLAUDE.md → Design):
   warm paper, dark ink, one red accent, a book serif for headings, ruled lines, square corners.
   The four answer colours stay, because they match the buttons players see on their phones. */

.editor {
    --paper: #f3eee4;
    --sheet: #fbf8f2;
    --ink: #1f1b16;
    --muted: #6b6257;
    --rule: #d6ccbb;
    --accent: #b3261e;
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    --r: 3px;
    min-height: 100vh;
    background: var(--paper);
    color: var(--ink);
    font-size: 17px;
}

.editor :focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.muted {
    color: var(--muted);
}

.small {
    font-size: 0.85rem;
}

/* ---------- Buttons (override the rounded game buttons from base.css) ---------- */

.editor .btn {
    padding: 0.55em 1em;
    border-radius: var(--r);
    background: transparent;
    box-shadow: inset 0 0 0 1.5px var(--ink);
    color: var(--ink);
    font-weight: 600;
    letter-spacing: 0;
    white-space: nowrap;
}

.editor .btn:hover:not(:disabled),
.editor .btn:active:not(:disabled) {
    transform: none;
    background: rgba(31, 27, 22, 0.06);
}

.editor .btn-primary {
    background: var(--accent);
    box-shadow: none;
    color: #fff;
}

.editor .btn-primary:hover:not(:disabled) {
    background: #921d17;
}

.editor .btn-ghost {
    box-shadow: inset 0 0 0 1px var(--rule);
}

.editor .btn-sm {
    font-size: 0.85rem;
    padding: 0.4em 0.8em;
}

.editor .icon-btn {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--r);
    color: var(--ink);
}

.editor .icon-btn:hover {
    background: rgba(31, 27, 22, 0.08);
}

.editor .icon-btn.danger:hover {
    background: rgba(179, 38, 30, 0.1);
    color: var(--accent);
}

.editor .icon-btn:disabled {
    opacity: 0.25;
    cursor: default;
    background: transparent;
}

.icon {
    display: block;
    width: 18px;
    height: 18px;
}

/* ---------- Header ---------- */

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    width: min(60rem, 100%);
    margin: 0 auto;
    padding: 1.25rem 1rem 0.75rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    color: inherit;
    text-decoration: none;
    font-family: var(--serif);
    font-size: 1.5rem;
    font-weight: 700;
}

.brand img {
    flex: none;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--r);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.user-photo {
    flex: none;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
}

.user-email {
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 0.9rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Layout ---------- */

.editor-main {
    width: min(60rem, 100%);
    margin: 0 auto;
    padding: 0 1rem 5rem;
}

.screen-center {
    display: flex;
    justify-content: center;
    padding-top: 10vh;
}

/* ---------- Auth ---------- */

.auth-card {
    width: min(26rem, 100%);
    padding: 2rem 0;
    border-top: 3px double var(--ink);
}

.auth-card h1 {
    margin: 0 0 0.5rem;
    font-family: var(--serif);
    font-size: 2rem;
}

.auth-card p {
    margin: 0;
}

.auth-card hr {
    border: 0;
    border-top: 1px solid var(--rule);
    margin: 1.5rem 0 1rem;
}

.google-btn {
    width: 100%;
    margin-top: 1.5rem;
}

.editor .google-btn {
    padding: 0.75em 1em;
    background: #fff;
    box-shadow: inset 0 0 0 1px var(--rule);
}

.auth-card .form-error {
    margin-top: 0.75rem;
}

.auth-switch {
    color: var(--muted);
}

.auth-switch a {
    color: var(--accent);
    font-weight: 600;
}

.form-error {
    margin: 0;
    color: var(--accent);
    font-weight: 600;
}

.form-error:empty {
    display: none;
}

/* ---------- Toolbar ---------- */

.toolbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    padding: 0.75rem 0;
    margin-bottom: 0.5rem;
    border-top: 3px double var(--ink);
    border-bottom: 1px solid var(--ink);
    background: var(--paper);
}

.toolbar-title {
    flex: 1 1 20rem;
    min-width: 0;
}

.game-name-input {
    display: block;
    width: 100%;
    padding: 0.2rem 0.4rem;
    margin-left: -0.4rem;
    border: 1px solid transparent;
    border-radius: var(--r);
    background: transparent;
    font-family: var(--serif);
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.25;
    text-overflow: ellipsis;
}

.game-name-input::placeholder {
    color: var(--muted);
    opacity: 0.7;
}

.game-name-input:hover {
    border-color: var(--rule);
}

.game-name-input:focus {
    border-color: var(--ink);
    outline: none;
    background: var(--sheet);
}

.save-status {
    display: block;
    min-height: 1.2em;
    color: var(--muted);
    font-size: 0.85rem;
}

.save-status.is-dirty {
    color: var(--accent);
}

.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ---------- Lobby background ---------- */

.lobby-setting {
    display: grid;
    grid-template-columns: 2.5rem minmax(0, 1fr);
    column-gap: 0.75rem;
    padding: 1rem 0 1.25rem;
    border-bottom: 1px solid var(--ink);
}

.lobby-setting > * {
    grid-column: 2;
}

.lobby-setting-title {
    margin: 0;
    font-family: var(--serif);
    font-size: 1.15rem;
    font-weight: 600;
}

.lobby-setting-hint {
    margin: 0.2rem 0 0.75rem;
}

.lobby-media {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem 0.9rem;
}

.lobby-media.is-uploading > :not(.media-progress) {
    opacity: 0.4;
    pointer-events: none;
}

.lobby-link-row {
    display: flex;
    gap: 0.5rem;
    flex: 0 1 30rem;
}

.lobby-link {
    flex: 1;
    min-width: 0;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--rule);
    border-radius: var(--r);
    background: var(--sheet);
}

.lobby-link:focus {
    border-color: var(--ink);
    outline: none;
}

.lobby-current {
    margin: 0;
}

.lobby-preview {
    width: 16rem;
    aspect-ratio: 16 / 9;
    background: #000;
    border: 1px solid var(--rule);
}

.lobby-preview .media-preview {
    width: 100%;
    height: 100%;
    max-height: none;
    object-fit: contain;
}

/* ---------- Questions ---------- */

.questions {
    display: flex;
    flex-direction: column;
}

.q-card {
    display: grid;
    grid-template-columns: 2.5rem minmax(0, 1fr);
    column-gap: 0.75rem;
    padding: 1.25rem 0;
    border-bottom: 1px solid var(--rule);
}

.q-number {
    grid-row: 1 / span 2;
    padding-top: 0.55rem;
    color: var(--muted);
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
}

.q-head {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    min-width: 0;
}

.q-text {
    flex: 1;
    min-width: 0;
    resize: none;
    overflow: hidden;
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--rule);
    border-radius: var(--r);
    background: var(--sheet);
    font-family: var(--serif);
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.q-text::placeholder,
.answer-field textarea::placeholder {
    color: var(--muted);
    opacity: 0.75;
}

.q-text:focus {
    border-color: var(--ink);
    outline: none;
    background: #fff;
}

.q-summary {
    flex: 1;
    min-width: 0;
    padding: 0.45rem 0;
    overflow: hidden;
    font-family: var(--serif);
    font-size: 1.2rem;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.q-actions {
    flex: none;
    display: flex;
    gap: 0.1rem;
}

.q-body {
    grid-column: 2;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 13rem;
    gap: 1rem 1.5rem;
    margin-top: 0.9rem;
}

.q-answers {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
    align-content: start;
}

.q-hint {
    grid-column: 1 / -1;
    margin: 0.15rem 0 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.q-side {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 0;
}

.field-inline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.9rem;
}

.field-inline select {
    min-width: 0;
    padding: 0.35rem 0.4rem;
    border: 1px solid var(--rule);
    border-radius: var(--r);
    background: var(--sheet);
    font-size: 0.95rem;
}

.field-inline select:focus {
    border-color: var(--ink);
    outline: none;
}

/* ---------- Media ---------- */

.media-box {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 7.5rem;
    padding: 0.75rem;
    border: 1px dashed var(--muted);
    border-radius: var(--r);
    text-align: center;
    overflow: hidden;
}

.media-box.is-dragover {
    border-style: solid;
    border-color: var(--ink);
    background: var(--sheet);
}

.media-box.is-uploading > :not(.media-progress) {
    opacity: 0.4;
    pointer-events: none;
}

.media-box.has-media {
    padding: 0;
    border-style: solid;
    border-color: var(--rule);
    background: #000;
}

.media-preview {
    display: block;
    width: 100%;
    max-height: 12rem;
    object-fit: contain;
}

.media-remove {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border: 0;
    border-radius: var(--r);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    cursor: pointer;
}

.media-remove:hover {
    background: var(--accent);
}

.media-progress {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 4px;
    background: var(--rule);
}

.media-progress span {
    display: block;
    width: 0;
    height: 100%;
    background: var(--ink);
    transition: width 0.2s;
}

/* ---------- Answers ---------- */

.answer-field {
    --tile: var(--ans-red);
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    min-width: 0;
    padding: 0.35rem 0.4rem 0.35rem 0.35rem;
    border: 1px solid var(--rule);
    border-left: 4px solid var(--tile);
    border-radius: var(--r);
    background: var(--sheet);
}

.answer-field.blue {
    --tile: var(--ans-blue);
}

.answer-field.yellow {
    --tile: var(--ans-yellow);
}

.answer-field.green {
    --tile: var(--ans-green);
}

.answer-field:focus-within {
    border-color: var(--ink);
    border-left-color: var(--tile);
    background: #fff;
}

.answer-field.is-correct {
    border-color: var(--ink);
    border-left-color: var(--tile);
    background: #fff;
}

.answer-field .answer-letter {
    width: 1.75rem;
    height: 1.75rem;
    margin-top: 0.1rem;
    border-radius: var(--r);
    background: var(--tile);
    color: #fff;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 700;
}

.answer-field textarea {
    flex: 1;
    min-width: 0;
    padding: 0.3rem 0.2rem;
    border: 0;
    background: transparent;
    font-weight: 500;
    line-height: 1.35;
    resize: none;
    overflow: hidden;
    overflow-wrap: anywhere;
}

.answer-field textarea:focus {
    outline: none;
}

/* "Õige" checkbox: visible text, so it is obvious what it does. */
.correct-toggle {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.15rem;
    padding: 0.25rem 0.45rem;
    border-radius: var(--r);
    color: var(--muted);
    font-size: 0.85rem;
    cursor: pointer;
    user-select: none;
}

.correct-toggle:hover {
    background: rgba(31, 27, 22, 0.06);
    color: var(--ink);
}

.correct-toggle input {
    appearance: none;
    display: grid;
    place-items: center;
    width: 1.1rem;
    height: 1.1rem;
    margin: 0;
    border: 1.5px solid currentColor;
    border-radius: 2px;
    cursor: pointer;
}

.correct-toggle input::after {
    content: "";
    width: 0.3rem;
    height: 0.6rem;
    margin-top: -0.15rem;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    visibility: hidden;
}

.correct-toggle input:checked {
    border-color: var(--ink);
    background: var(--ink);
}

.correct-toggle input:checked::after {
    visibility: visible;
}

.correct-toggle input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.is-correct .correct-toggle {
    color: var(--ink);
    font-weight: 700;
}

.add-question {
    display: block;
    width: 100%;
    margin-top: 1.25rem;
    padding: 0.9rem;
    border: 1px dashed var(--muted);
    border-radius: var(--r);
    background: transparent;
    color: var(--ink);
    font-weight: 600;
    cursor: pointer;
}

.add-question:hover {
    border-style: solid;
    border-color: var(--ink);
    background: var(--sheet);
}

/* ---------- Saved quizzes dialog ---------- */

.games-dialog {
    width: min(30rem, calc(100vw - 2rem));
    max-height: 75vh;
    padding: 1.25rem 1.5rem 1.5rem;
    border: 1px solid var(--ink);
    border-radius: var(--r);
    background: var(--paper);
    color: var(--ink);
    box-shadow: 0 12px 40px rgba(31, 27, 22, 0.25);
}

.games-dialog::backdrop {
    background: rgba(31, 27, 22, 0.4);
}

.dialog-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--ink);
}

.dialog-head h2 {
    margin: 0;
    font-family: var(--serif);
    font-size: 1.4rem;
}

.games-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.games-list > li {
    padding: 0.6rem 0;
}

.games-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    border-bottom: 1px solid var(--rule);
}

.games-list > li.games-item {
    padding: 0;
}

.games-open {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
    min-width: 0;
    padding: 0.7rem 0;
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.games-open strong {
    max-width: 100%;
    overflow: hidden;
    font-family: var(--serif);
    font-size: 1.15rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.games-open:hover strong,
.games-open:focus-visible strong {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* ---------- Spinner & toast ---------- */

.editor .spinner {
    border-color: var(--rule);
    border-top-color: var(--ink);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    z-index: 100;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100vw - 2rem);
    padding: 0.7rem 1.1rem;
    border-radius: var(--r);
    background: var(--ink);
    color: #fff;
    font-weight: 600;
}

/* ---------- Narrow screens ---------- */

@media (max-width: 760px) {
    .q-body {
        grid-template-columns: minmax(0, 1fr);
    }

    .q-side {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }

    .q-side .media-box {
        flex: 1 1 100%;
    }

    .q-side .media-box:not(.has-media) {
        flex-direction: row;
        flex-wrap: wrap;
        min-height: 0;
        padding: 0.6rem;
    }
}

@media (max-width: 600px) {
    .editor {
        font-size: 16px;
    }

    .user-email {
        display: none;
    }

    .toolbar {
        position: static;
    }

    .game-name-input {
        font-size: 1.4rem;
    }

    .toolbar-actions {
        width: 100%;
    }

    .toolbar-actions .btn {
        flex: 1 1 auto;
    }

    #host-button {
        flex-basis: 100%;
    }

    /* Number and actions on one line, then the question and answers full width. */
    .q-card {
        grid-template-columns: minmax(0, 1fr);
    }

    .q-number {
        grid-area: 1 / 1;
        padding-top: 0.5rem;
    }

    .q-head {
        display: contents;
    }

    .q-actions {
        grid-area: 1 / 1;
        justify-self: end;
    }

    .q-text,
    .q-summary {
        grid-area: 2 / 1;
        margin-top: 0.25rem;
    }

    .q-body {
        grid-column: 1;
    }

    .q-answers {
        grid-template-columns: minmax(0, 1fr);
    }
}
