/* iterciter — Sequence Memorization UI */

body { margin: 0; font-family: sans-serif; background: #f8f8f8; }

#iterciter {
    max-width: 720px;
    margin: 1em auto;
    padding: 0 1em;
}

/* Toolbar */
#toolbar {
    display: flex;
    align-items: center;
    gap: 0.5em;
    flex-wrap: wrap;
    padding: 0.4em 0;
    margin-bottom: 0.5em;
    background: #f8f8f8;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid #ddd;
}
#back-link a { font-size: 0.85em; color: #888; text-decoration: none; }
#unit-picker {
    font-size: 1.05em;
    padding: 0.35em 0.6em;
    border: 1px solid #bbb;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    color: #333;
    min-width: 14em;
    flex: 1;
}
#btn-edit-unit {
    font-size: 0.9em; padding: 0.3em 0.6em;
    border: 1px solid #bbb; border-radius: 4px;
    background: #fff; cursor: pointer;
}
#add-unit { font-size: 0.9em; color: #666; }
#add-unit summary { cursor: pointer; }
#ui-controls { display: contents; }
#btn-area { display: contents; }

/* Sequence display */
#sequence {
    margin: 1em 0;
    border-left: 3px solid #ccc;
    padding-left: 1em;
}
#sequence[dir="rtl"] { border-left: none; border-right: 3px solid #ccc; padding-left: 0; padding-right: 1em; }

.seg-row {
    display: flex;
    align-items: center;
    padding: 0.4em 0;
    font-size: 1.1em;
    line-height: 1.5;
    border-bottom: 1px solid #eee;
    transition: background 0.15s;
}
.seg-text { flex: 1; }
.seg-row.past    { color: #555; }
.seg-row.focus   { background: #fffbe6; font-weight: bold; border-left: 3px solid #f0a500; margin-left: -1em; padding-left: calc(1em - 3px); }
.seg-row.hidden  { color: #ccc; font-style: italic; }
.seg-row.cursor  { background: #e8f4fd; }

#sequence[dir="rtl"] .seg-row.focus { border-left: none; border-right: 3px solid #f0a500; margin-left: 0; padding-left: 0; margin-right: -1em; padding-right: calc(1em - 3px); }

.seg-hidden-placeholder { color: #bbb; }

/* TG expansion (on reveal) */
.tg-expansion { margin: 0.3em 0 0.2em 1em; font-size: 0.9em; color: #444; }
.tg-expansion[dir="rtl"] { margin-left: 0; margin-right: 1em; }
.tg-tier { display: block; }
.tg-tier .tier-label { color: #999; font-size: 0.85em; margin-right: 0.4em; }

#btn-next    { background: #4a9;    color: #fff; padding: 0.5em 1.2em; font-size: 1em; border: none; border-radius: 4px; cursor: pointer; }
#btn-peek    { background: #e8a020; color: #fff; padding: 0.5em 1.2em; font-size: 1em; border: none; border-radius: 4px; cursor: pointer; }
#btn-restart { background: #aaa;    color: #fff; padding: 0.35em 0.8em; font-size: 0.85em; border: none; border-radius: 4px; cursor: pointer; }
#btn-next:disabled, #btn-peek:disabled { opacity: 0.4; cursor: default; }

.gloss-toggle {
    font-size: 0.9em;
    color: #666;
    margin-left: 0.4em;
    cursor: pointer;
    white-space: nowrap;
}
.gloss-toggle input { vertical-align: middle; margin-right: 0.2em; }

.level-select { font-size: 0.9em; color: #666; white-space: nowrap; }
.level-select select {
    font-size: 0.95em;
    padding: 0.35em 0.6em;
    border: 1px solid #bbb;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    color: #333;
}

/* Status bar */
#status {
    font-size: 0.85em;
    color: #888;
    margin: 0.4em 0 1em;
}

/* History strips — right side of row, overflow right for old history */
.seg-strips {
    display: flex;
    flex-direction: row;
    align-items: center;
    height: 10px;
    margin-left: 0.8em;
    flex-shrink: 0;
    overflow: visible;
}
.strip {
    width: 5px; height: 10px;
    margin-right: 1px;
    flex-shrink: 0;
}
.strip.green { background: #4a9; }
.strip.red   { background: #e44; }
.strip-divider {
    width: 3px; height: 14px;
    background: #888;
    margin: 0 2px;
    flex-shrink: 0;
}
.strip-divider.done { background: #4a9; }
.streak-badge {
    font-size: 0.6em; color: #4a9; margin: 0 2px; flex-shrink: 0;
    line-height: 10px; vertical-align: middle;
}

/* Quiz mode — multiple-choice options */
.quiz-prompt {
    font-size: 0.9em;
    color: #888;
    margin-bottom: 0.5em;
    font-weight: normal;
}
.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 0.3em;
    font-weight: normal;
}
.quiz-option {
    display: flex;
    align-items: baseline;
    gap: 0.5em;
    padding: 0.45em 0.7em;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 0.95em;
    line-height: 1.4;
    transition: background 0.1s;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
}
.quiz-option:hover { background: #f0f6ff; }
.quiz-option:active { background: #e0ecfa; }
.quiz-num {
    flex-shrink: 0;
    width: 1.3em;
    text-align: center;
    color: #999;
    font-size: 0.85em;
}
.quiz-option.eliminated {
    text-decoration: line-through;
    color: #c44;
    background: #fef0f0;
    border-color: #e88;
    cursor: default;
    opacity: 0.6;
}
.quiz-option.eliminated:hover { background: #fef0f0; }
.quiz-option.correct {
    background: #4a9 !important;
    color: #fff !important;
    border-color: #3a8 !important;
}

/* Script-IPA pair grid (ScriptUI) */
#script-grid { margin: 1em 0; }
.script-grid-inner { display: flex; flex-wrap: wrap; gap: 0.6em 0.5em; }
.script-col {
    display: flex; flex-direction: column; align-items: center;
    min-width: 1.6em; padding: 0.2em 0.3em;
    border: 1px solid #eee; border-radius: 4px; background: #fff;
}
.script-cell {
    line-height: 1.2; padding: 0.05em 0.1em; min-height: 1.4em;
    display: flex; align-items: center; justify-content: center;
}
.script-cell.tier-l2  { font-size: 1.7em; }
.script-cell.tier-ipa { font-size: 1em; color: #666; border-top: 1px dotted #ddd; min-width: 1.6em; }
.script-cell.last     { background: #fffbe6; border-radius: 3px; }
.script-col.quiz-active { border-color: #f0a500; background: #fffbe6; box-shadow: 0 0 0 2px #f0a500; }
.script-col.mastered { opacity: 0.6; border-color: #4a9; }
.script-col.just-mastered { opacity: 1; font-weight: bold; border-color: #4a9; border-width: 2px; }
.script-cell.quiz-hint { color: #333; font-weight: bold; }
.script-cell.quiz-target { color: #f0a500; font-weight: bold; font-size: 1.3em; }
.col-strips { display: flex; justify-content: center; gap: 2px; padding: 2px 0; }
.script-separator {
    width: 2px; align-self: stretch; background: #4a9; margin: 0 0.3em; flex-shrink: 0;
}
#btn-reset { background: #c44; color: #fff; padding: 0.35em 0.8em; font-size: 0.85em; border: none; border-radius: 4px; cursor: pointer; }
.quiz-panel { margin-top: 1em; }
.quiz-options-row { flex-direction: row; flex-wrap: wrap; }
.quiz-options-row .quiz-option {
    flex: 0 0 auto;
    min-width: 2.5em;
    text-align: center;
    justify-content: center;
    padding: 0.5em 0.7em;
}
.quiz-options-row .quiz-num { width: auto; margin-right: 0.3em; }
.quiz-prompt-value { font-size: 1.4em; font-weight: bold; }
.quiz-toggle { font-size: 0.9em; color: #666; margin-left: 0.4em; cursor: pointer; white-space: nowrap; }
.quiz-toggle input { vertical-align: middle; margin-right: 0.2em; }

/* Mobile: script quiz goes full-size, hide unrevealed grid clutter */
@media (max-width: 600px) {
    #iterciter { padding: 0 0.5em; }
    #toolbar { gap: 0.3em; padding: 0.3em 0; font-size: 0.85em; }
    #unit-picker { min-width: 8em; font-size: 0.95em; }

    .script-col.unrevealed { display: none; }

    .script-col.quiz-active {
        padding: 0.4em 0.8em;
    }
    .script-col.quiz-active .script-cell.tier-l2 { font-size: 3em; }
    .script-col.quiz-active .script-cell.tier-ipa { font-size: 1.6em; }
    .script-col.quiz-active .script-cell.quiz-target { font-size: 2.5em; }

    .script-col.mastered .script-cell.tier-l2 { font-size: 1.3em; }
    .script-col.mastered .script-cell.tier-ipa { font-size: 0.85em; }

    .quiz-panel { margin-top: 0.6em; }
    .quiz-options-row .quiz-option {
        font-size: 1.3em;
        padding: 0.6em 0.8em;
        min-width: 3em;
        min-height: 2.5em;
    }
    .quiz-options-row .quiz-num { font-size: 0.7em; }

    .seg-row { font-size: 1em; }
    .quiz-options .quiz-option { font-size: 1.05em; padding: 0.6em 0.8em; min-height: 2.5em; }
}

/* ===== Mobile full-screen script quiz (BaseThing-style screens) ===== */
.sm-root {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: #fff;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.sm-screen {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.6em;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}
.sm-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.2em 0;
    font-size: 0.95em;
    color: #888;
    flex-shrink: 0;
}
.sm-status button {
    background: none;
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 0.3em 0.7em;
    font-size: 1.1em;
    cursor: pointer;
    color: #555;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sm-hint {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 5vh;
}
.sm-hint-char { font-size: 6em; line-height: 1.2; max-width: 90vw; text-align: center; overflow-wrap: break-word; }
.sm-hint-label { font-size: 1.1em; color: #888; margin-top: 0.3em; text-align: center; }
.sm-streak { text-align: center; padding: 0.2em 0; flex-shrink: 0; }
.sm-streak-dot {
    display: inline-block; width: 10px; height: 10px;
    border-radius: 50%; background: #4a9; margin: 0 2px;
}
.sm-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 0;
    flex-shrink: 0;
}
.sm-option {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.1em 0.1em;
    font-size: min(4em, 11vh);
    line-height: 1.15;
    border: 2px solid #ccc;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
    transition: background 0.1s;
}
.sm-option:active { background: #e0ecfa; }
.sm-option.eliminated {
    text-decoration: line-through;
    color: #c44;
    background: #fef0f0;
    border-color: #e88;
    opacity: 0.5;
    cursor: default;
}
.sm-option.eliminated:active { background: #fef0f0; }
.sm-option-full { grid-column: 1 / -1; }
.sm-done {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.5em;
    min-height: 40vh;
    font-size: 1.2em;
}
.sm-next-pass {
    margin-top: 1em;
    padding: 0.8em 1.5em;
    font-size: 1.2em;
    background: #4a9;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    min-height: 44px;
}
.sm-nav-hint {
    text-align: center;
    font-size: 0.75em;
    color: #bbb;
    padding: 0.3em 0;
    flex-shrink: 0;
}
.sm-grid-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3em 0;
    flex-shrink: 0;
}
.sm-grid-header button {
    background: none;
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 0.4em 0.8em;
    font-size: 1em;
    cursor: pointer;
    color: #555;
    min-height: 44px;
}
.sm-grid-header span { font-size: 0.95em; color: #888; }
.sm-pairs-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
    padding: 0.5em 0;
    flex: 1;
    align-content: flex-start;
    overflow-y: auto;
}
.sm-pair {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.4em 0.5em;
    border: 1px solid #ddd;
    border-radius: 6px;
    min-width: 3.5em;
    background: #fff;
}
.sm-pair.mastered { border-color: #4a9; background: #f0faf5; }
.sm-pair-char { font-size: 2em; line-height: 1.2; }
.sm-pair-pron { font-size: 0.85em; color: #666; margin-top: 0.1em; }
.sm-pair-dots { display: flex; gap: 3px; margin-top: 3px; }
.sm-controls {
    flex-shrink: 0;
    padding: 0.8em 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.6em;
    align-items: center;
    border-top: 1px solid #eee;
    margin-top: 0.5em;
}
.sm-controls select {
    font-size: 1em;
    padding: 0.4em 0.6em;
    border: 1px solid #bbb;
    border-radius: 6px;
    background: #fff;
    color: #333;
    min-height: 44px;
}
.sm-controls button {
    padding: 0.5em 1em;
    font-size: 1em;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: #fff;
    min-height: 44px;
}

/* Memorization mobile additions */
.sm-context { flex-shrink: 0; padding: 0.3em 0; }
.sm-context-line {
    font-size: 0.95em;
    color: #999;
    padding: 0.15em 0;
    white-space: nowrap;
    overflow: hidden;
}
.sm-context-line:last-child { color: #555; }
.sm-prompt {
    font-size: 0.9em;
    color: #888;
    padding: 0.2em 0;
    text-align: center;
    flex-shrink: 0;
}
.sm-options-col {
    display: block;
    padding: 0.2em 0 0.5em;
    flex: 1;
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.sm-option-text {
    display: flex;
    align-items: center;
    gap: 0.4em;
    padding: 0.4em 0.6em;
    font-size: 0.9em;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    min-height: 2em;
    line-height: 1.2;
    white-space: nowrap;
    width: max-content;
    min-width: 100%;
    margin-bottom: 0.25em;
    box-sizing: border-box;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
    transition: background 0.1s;
}
.sm-option-text:active { background: #e0ecfa; }
.sm-option-text.eliminated {
    text-decoration: line-through;
    color: #c44;
    background: #fef0f0;
    border-color: #e88;
    opacity: 0.5;
    cursor: default;
}
.sm-option-text.eliminated:active { background: #fef0f0; }
.sm-option-num {
    flex-shrink: 0;
    width: 1.3em;
    text-align: center;
    color: #999;
    font-size: 0.85em;
}
.sm-seg-row {
    display: flex;
    align-items: center;
    padding: 0.35em 0;
    border-bottom: 1px solid #f0f0f0;
    gap: 0.4em;
}
.sm-seg-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    font-size: 0.95em;
}
.sm-seg-row.past .sm-seg-text { color: #888; }
.sm-seg-row.focus .sm-seg-text { color: #333; font-weight: bold; }
.sm-seg-row.hidden .sm-seg-text { color: #ccc; font-style: italic; }
.sm-peek-btn, .sm-next-btn {
    display: block;
    width: 100%;
    padding: 0.8em;
    font-size: 1.2em;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    min-height: 44px;
    margin-bottom: 0.4em;
    flex-shrink: 0;
}
.sm-peek-btn { background: #e8a020; }
.sm-next-btn { background: #4a9; }

/* Mobile dashboard */
.sm-dash-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.5em 0; flex-shrink: 0; border-bottom: 1px solid #eee; margin-bottom: 0.5em;
}
.sm-dash-title { margin: 0; font-size: 1.3em; color: #333; font-weight: bold; }
.sm-dash-add {
    background: #4a9; color: #fff; border: none; border-radius: 6px;
    padding: 0.4em 0.8em; font-size: 1em; cursor: pointer; min-height: 44px;
}
.sm-unit-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sm-unit-card {
    padding: 0.7em 0.8em; border: 1px solid #ddd; border-radius: 8px;
    margin-bottom: 0.5em; background: #fff; cursor: pointer;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
}
.sm-unit-card:active { background: #f0f6ff; }
.sm-unit-title { font-size: 1.05em; color: #333; line-height: 1.3; }
.sm-unit-meta { font-size: 0.85em; color: #888; margin-top: 0.2em; }
.sm-unit-bar {
    height: 4px; background: #eee; border-radius: 2px; margin-top: 0.4em; overflow: hidden;
}
.sm-unit-bar-fill { height: 100%; background: #4a9; border-radius: 2px; }
.sm-section-label {
    font-size: 0.8em; color: #999; text-transform: uppercase; letter-spacing: 0.05em;
    padding: 0.8em 0 0.3em; flex-shrink: 0;
}
.sm-add-field { margin-bottom: 0.8em; }
.sm-add-field label { display: block; font-size: 0.9em; color: #666; margin-bottom: 0.2em; }
.sm-add-field textarea, .sm-add-field input[type="text"], .sm-add-field select {
    width: 100%; box-sizing: border-box; font-size: 1em; padding: 0.5em;
    border: 1px solid #ccc; border-radius: 6px; font-family: inherit;
}
.sm-add-field textarea { min-height: 10em; resize: vertical; }
.sm-add-submit {
    background: #4a9; color: #fff; border: none; border-radius: 8px;
    padding: 0.7em 1.2em; font-size: 1.1em; cursor: pointer; min-height: 44px; width: 100%;
}

/* Correct-answer flash */
.sm-option.correct, .sm-option-text.correct {
    background: #4a9 !important;
    color: #fff !important;
    border-color: #3a8 !important;
    transition: background 0.1s;
}

/* Pair reveal — Saussure sign display after missed quiz */
.pair-reveal-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.45s ease;
}
.pair-reveal-overlay.visible { opacity: 1; }
.pair-reveal-overlay.exiting { background: transparent; transition: background 1.6s ease; }
.pair-reveal-card {
    background: #fff; border-radius: 16px; padding: 1.5em 2.5em;
    text-align: center; box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    transform: scale(0.5); transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.pair-reveal-overlay.visible .pair-reveal-card { transform: scale(1); }
.pair-reveal-overlay.exiting .pair-reveal-card {
    transform: scale(0.3) translateY(-240px);
    opacity: 0;
    transition: transform 1.6s cubic-bezier(0.4, 0, 1, 1), opacity 1.6s cubic-bezier(0.8, 0, 1, 1);
}
.pair-reveal-signifier { font-size: min(5em, 25vw); line-height: 1.2; }
.pair-reveal-bar {
    height: 3px; background: #333; margin: 0.3em auto;
    width: 80%; border-radius: 2px;
}
.pair-reveal-signified { font-size: min(2.5em, 12vw); color: #444; line-height: 1.3; }
.pair-reveal-sub { font-size: 0.9em; color: #888; margin-top: 0.2em; }
