:root {
    --paper: #f5efe3;
    --surface: #fffefb;
    --surface-soft: #fbf5e8;
    --ink: #2b231c;
    --muted: #6b6258;
    --line: #e3d8ca;
    --brick: #c8542c;
    --brick-dark: #9e3e25;
    --brick-soft: #f8e5d8;
    --moss: #6b8e5a;
    --moss-soft: #e4ecde;
    --info: #315c7a;
    --info-soft: #dcebf1;
    --danger: #b5462e;
    --shadow: 0 12px 24px rgba(43, 35, 28, 0.11);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0)),
        var(--paper);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

button,
input,
select {
    font: inherit;
}

.v2-shell {
    width: min(100% - 28px, 1120px);
    margin: 0 auto;
    padding: 28px 0 40px;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.eyebrow,
.rail-label {
    margin: 0 0 6px;
    color: var(--brick);
    font-size: 0.76rem;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(2.1rem, 4vw, 4.3rem);
    line-height: 0.95;
    letter-spacing: 0;
}

.preview-badge {
    flex: 0 0 auto;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 9px 13px;
    background: var(--surface);
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 800;
}

.top-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.auth-panel {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px;
    background: var(--surface);
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 900;
}

.auth-panel .mini-btn {
    min-height: 32px;
    padding: 0 11px;
    border-radius: 999px;
}

.access-badge {
    border-color: #bfd3b5;
    background: var(--moss-soft);
    color: #3e5d32;
}

.task-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    align-items: end;
    gap: 10px;
    margin-bottom: 14px;
}

.quick-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: -2px 0 14px;
}

.section-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 0 0 14px;
}

.section-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font-weight: 900;
    text-decoration: none;
}

.section-tab.active {
    border-color: var(--brick);
    background: var(--brick);
    color: #fffefb;
    box-shadow: 0 3px 0 var(--brick-dark), 0 8px 16px rgba(200, 84, 44, 0.18);
}

.field {
    display: grid;
    gap: 6px;
}

.field span {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
}

.field input,
.field select {
    height: 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0 12px;
    background: var(--surface);
    color: var(--ink);
}

.tool-btn,
.mini-btn,
.stage-link,
.icon-btn {
    border: 0;
    border-radius: var(--radius);
    min-height: 44px;
    cursor: pointer;
    font-weight: 900;
    text-decoration: none;
}

.tool-btn,
.stage-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 18px;
    background: var(--brick);
    color: #fffefb;
    box-shadow: 0 3px 0 var(--brick-dark), 0 8px 16px rgba(200, 84, 44, 0.22);
}

.tool-btn:active,
.stage-link:active,
.brick-btn:active {
    transform: translateY(1px);
}

.tool-btn.ghost,
.mini-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 13px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    box-shadow: none;
}

.tool-btn:disabled,
.mini-btn:disabled,
.icon-btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    transform: none;
}

.mini-btn.danger {
    border-color: #e0b094;
    background: #fff1e8;
    color: var(--brick);
}

.practice-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 18px;
    align-items: start;
}

.dictionary-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 18px;
    align-items: start;
}

.practice-stage,
.dictionary-main,
.stage-card,
.stats-panel,
.wordbook-panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.practice-stage {
    min-height: 640px;
    padding: clamp(18px, 3vw, 32px);
}

.dictionary-main {
    padding: clamp(18px, 3vw, 28px);
}

.word-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.topic-pill {
    display: inline-flex;
    margin-bottom: 8px;
    border-radius: 999px;
    padding: 5px 10px;
    background: var(--info-soft);
    color: var(--info);
    font-size: 0.78rem;
    font-weight: 900;
}

#word-display {
    position: relative;
    top: -0.06em;
    margin: 0;
    overflow-wrap: anywhere;
    font-size: clamp(2.1rem, 6.3vw, 4.62rem);
    line-height: 1;
    letter-spacing: 0;
}

.word-meta {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 1rem;
    font-weight: 800;
}

.icon-btn {
    width: 56px;
    min-width: 56px;
    height: 56px;
    border: 2px solid var(--brick);
    background: var(--surface);
    color: var(--brick);
    font-size: 1rem;
}

.icon-btn.playing {
    background: var(--brick-soft);
}

.example-line {
    max-width: 52ch;
    margin: 18px 0 10px;
    color: var(--muted);
    font-size: 1.05rem;
    line-height: 1.55;
}

.example-line.locked {
    color: var(--info);
    font-weight: 800;
}

.audio-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 0 0 20px;
}

.status-field {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0 10px;
    background: var(--surface);
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 900;
}

.status-field select {
    height: 32px;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-weight: 900;
}

.answer-lane {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.answer-tools {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.answer-slots {
    display: flex;
    flex: 1;
    flex-wrap: wrap;
    gap: 10px;
}

.slot {
    display: grid;
    grid-template-rows: 14px 1fr;
    align-items: center;
    justify-items: center;
    width: 76px;
    min-height: 76px;
    border: 2px dashed #cfbca8;
    border-radius: var(--radius);
    background: var(--surface-soft);
    color: var(--muted);
    font-weight: 900;
    padding: 7px 4px 6px;
}

.slot.filled {
    border-style: solid;
    border-color: var(--moss);
    background: var(--moss-soft);
    color: var(--ink);
}

.slot.wrong {
    border-color: var(--danger);
    background: #f8ded6;
}

.slot.stressed {
    border-color: #cfbca8;
    background: var(--surface-soft);
}

.slot.filled.stressed {
    border-color: var(--moss);
    background: var(--moss-soft);
}

.slot.wrong.stressed {
    border-color: var(--danger);
    background: #f8ded6;
}

.slot-stress-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #d4c7ba;
}

.slot.stressed .slot-stress-dot {
    background: #111;
}

.slot-value {
    display: grid;
    place-items: center;
    min-height: 48px;
    color: var(--ink);
    font-size: 0.78rem;
}

.slot-value img {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.hint-strip {
    display: none;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-height: 0;
    margin: 0 0 12px;
}

.hint-strip.is-visible {
    display: flex;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px;
    background: var(--surface-soft);
}

.hint-label {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 900;
}

.stress-dot-row {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 11px;
    background: var(--surface);
}

.stress-dot-v2 {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #d4c7ba;
}

.stress-dot-v2.stressed {
    background: #111;
}

.hint-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 5px 9px;
    background: var(--surface);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 900;
}

.hint-chip img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.hint-chip.strong {
    border-color: #e0b094;
    background: #fff1e8;
    color: var(--brick);
}

.brick-board {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
    gap: 12px;
}

.brick-btn {
    display: grid;
    place-items: center;
    min-height: 78px;
    border: 2px solid #332820;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 4px 0 #332820, 0 10px 16px rgba(43, 35, 28, 0.16);
    cursor: pointer;
}

.brick-btn img {
    width: 66px;
    max-width: 86%;
    height: 66px;
    object-fit: contain;
}

.brick-btn.selected {
    border-color: var(--brick);
    background: var(--brick-soft);
}

.feedback {
    margin-top: 20px;
    border-left: 4px solid var(--info);
    border-radius: var(--radius);
    padding: 13px 15px;
    background: var(--info-soft);
    color: var(--ink);
    font-weight: 800;
    line-height: 1.45;
}

.feedback.good {
    border-left-color: var(--moss);
    background: var(--moss-soft);
}

.feedback.bad {
    border-left-color: var(--danger);
    background: #f8ded6;
}

.wrong-overlay {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    margin-top: 12px;
    border: 1px solid #e0b094;
    border-radius: var(--radius);
    padding: 12px;
    background: #fff1e8;
}

.wrong-overlay[hidden] {
    display: none;
}

.wrong-overlay strong {
    display: block;
    margin-bottom: 4px;
}

.wrong-hint-text {
    margin: 0;
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 800;
    line-height: 1.45;
}

.wrong-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.side-rail {
    display: grid;
    gap: 14px;
}

.stage-card,
.stats-panel,
.wordbook-panel {
    padding: 18px;
}

.stage-card {
    background: linear-gradient(180deg, var(--moss-soft), var(--surface));
    border-color: #bfd3b5;
}

.stage-card h2 {
    margin-bottom: 8px;
    font-size: 1.3rem;
}

.stage-card p {
    color: var(--muted);
    line-height: 1.5;
}

.stage-link {
    width: 100%;
    min-height: 48px;
    background: var(--moss);
    box-shadow: 0 3px 0 #506f42, 0 8px 16px rgba(80, 111, 66, 0.2);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.stat-grid div {
    min-height: 86px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    background: var(--surface-soft);
}

.stat-grid strong {
    display: block;
    font-size: 1.9rem;
    line-height: 1;
}

.stat-grid span,
.wordbook-item span {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
}

.wordbook-list {
    display: grid;
    gap: 8px;
}

.wordbook-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px;
    background: var(--surface-soft);
}

.wordbook-item strong {
    overflow-wrap: anywhere;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(43, 35, 28, 0.42);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-panel {
    width: min(100%, 920px);
    max-height: min(86vh, 820px);
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 22px 50px rgba(43, 35, 28, 0.22);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--line);
    padding: 16px 18px;
    background: var(--surface-soft);
}

.modal-head h2 {
    margin: 0;
    font-size: 1.25rem;
}

.icon-btn.small {
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    border-color: var(--line);
    color: var(--ink);
    font-size: 1.2rem;
}

.modal-body {
    max-height: calc(min(86vh, 820px) - 72px);
    overflow: auto;
    padding: 18px;
}

.modal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.metric {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    background: var(--surface-soft);
}

.metric strong {
    display: block;
    font-size: 1.8rem;
    line-height: 1;
}

.metric span {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 900;
}

.panel-section {
    margin-top: 16px;
}

.panel-section h3 {
    margin: 0 0 10px;
    font-size: 1rem;
}

.data-list {
    display: grid;
    gap: 8px;
}

.data-row,
.leaderboard-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 12px;
    background: var(--surface);
}

.data-row .muted,
.leaderboard-row .muted {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.pd-manager {
    display: grid;
    gap: 14px;
}

.pd-add-box,
.pd-filter-box,
.pd-bulk-toolbar {
    display: grid;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    background: var(--surface-soft);
}

.pd-add-box h2,
.pd-filter-box h2,
.panel-section h2 {
    margin: 0 0 4px;
    font-size: 1rem;
}

.pd-add-row,
.pd-filter-row,
.pd-bulk-toolbar {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    align-items: end;
}

.pd-add-row,
.pd-filter-row {
    display: grid;
}

.pd-add-box input,
.pd-add-box textarea,
.pd-add-box select,
.pd-filter-box input,
.pd-filter-box select,
.pd-bulk-toolbar select,
.pd-row select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px 10px;
    background: var(--surface);
    color: var(--ink);
}

.mini-btn.danger {
    border-color: #e3b0a3;
    color: var(--danger);
    background: #fff6f3;
}

.pd-add-box textarea {
    min-height: 86px;
    resize: vertical;
}

.pd-result-list,
.pd-list {
    display: grid;
    gap: 8px;
}

.pd-row {
    display: grid;
    grid-template-columns: 28px minmax(110px, 1.2fr) minmax(130px, 1fr) 96px 76px 96px auto;
    gap: 8px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px;
    background: var(--surface);
}

.pd-row.archived {
    opacity: 0.72;
    background: #f4eee6;
}

.pd-select {
    display: grid;
    justify-items: center;
    gap: 4px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 900;
    cursor: pointer;
    user-select: none;
}

.pd-select input {
    width: 20px;
    height: 20px;
    accent-color: var(--brick);
}

.pd-word strong {
    display: block;
}

.pd-word span,
.pd-meta,
.pd-added {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 800;
}

.pd-status-badge {
    justify-self: start;
    border-radius: 999px;
    padding: 5px 9px;
    background: var(--info-soft);
    color: var(--info);
    font-size: 0.78rem;
    font-weight: 900;
}

.pd-status-badge.review {
    background: #fff1e8;
    color: var(--brick);
}

.pd-status-badge.learned {
    background: var(--moss-soft);
    color: #3e5d32;
}

.pd-status-badge.archived {
    background: #eee5dc;
    color: var(--muted);
}

.pd-row-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.report-trend-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.trend-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #f8ded6;
    color: var(--danger);
    font-weight: 900;
}

.trend-mark.ok {
    background: var(--moss-soft);
    color: #3e5d32;
}

.comparison-grid,
.timeseries-list {
    display: grid;
    gap: 8px;
}

.comparison-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.comparison-cell {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    background: var(--surface-soft);
}

.comparison-cell strong {
    display: block;
    font-size: 1.4rem;
}

.leaderboard-row {
    grid-template-columns: 44px minmax(0, 1fr) 96px;
}

.leaderboard-row.self {
    border-color: #bfd3b5;
    background: var(--moss-soft);
}

.report-word {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
}

.code-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.code-strip img {
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 4px;
    background: var(--surface);
}

@media (prefers-reduced-motion: no-preference) {
    .tool-btn,
    .stage-link,
    .brick-btn,
    .icon-btn {
        transition: transform 0.14s ease, background 0.14s ease, box-shadow 0.14s ease;
    }

    .brick-btn:hover,
    .tool-btn:hover,
    .stage-link:hover,
    .icon-btn:hover {
        transform: translateY(-1px);
    }
}

@media (max-width: 860px) {
    .practice-layout,
    .dictionary-layout {
        grid-template-columns: 1fr;
    }

    .side-rail {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .pd-row {
        grid-template-columns: 28px minmax(0, 1fr) minmax(120px, 0.8fr);
    }

    .pd-status-badge,
    .pd-added,
    .pd-row select,
    .pd-row-actions {
        grid-column: auto;
    }

    .pd-row-actions {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }
}

@media (max-width: 640px) {
    .v2-shell {
        width: min(100% - 24px, 420px);
        padding-top: 20px;
    }

    .topbar {
        display: grid;
    }

    .task-strip {
        grid-template-columns: 1fr 1fr;
    }

    .section-tabs {
        grid-template-columns: 1fr;
    }

    .quick-tools,
    .audio-row {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .search-field {
        grid-column: 1 / -1;
    }

    .practice-stage {
        min-height: auto;
        padding: 18px;
    }

    .word-row {
        align-items: center;
    }

    #word-display {
        font-size: clamp(1.96rem, 12.6vw, 3.08rem);
    }

    .answer-lane {
        align-items: stretch;
        flex-direction: column;
    }

    .answer-tools {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .slot {
        width: 64px;
        min-height: 76px;
    }

    .brick-board {
        grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
    }

    .brick-btn {
        min-height: 66px;
    }

    .brick-btn img {
        width: 54px;
        height: 54px;
    }

    .side-rail {
        grid-template-columns: 1fr;
    }

    .leaderboard-row {
        grid-template-columns: 34px minmax(0, 1fr);
    }

    .leaderboard-row > strong:last-child {
        grid-column: 2;
    }

    .wrong-overlay,
    .pd-row {
        grid-template-columns: 1fr;
    }

    .wrong-actions,
    .pd-row-actions {
        justify-content: stretch;
    }

    .wrong-actions .mini-btn,
    .pd-row-actions .mini-btn {
        flex: 1 1 auto;
    }
}
