:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --text: #1f2933;
    --muted: #64748b;
    --line: #d9e1ea;
    --primary: #246bfe;
    --primary-soft: #e8f0ff;
    --success: #14824a;
    --warning: #a56300;
    --danger: #c7352d;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-tap-highlight-color: transparent;
}

a {
    color: inherit;
    text-decoration: none;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand {
    font-weight: 800;
}

.topbar nav {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 15px;
}

.context-bar {
    display: flex;
    gap: 12px;
    align-items: end;
    justify-content: space-between;
    padding: 10px 20px;
    background: #eef3f8;
    border-bottom: 1px solid var(--line);
}

.context-bar form {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) minmax(170px, 1fr);
    gap: 10px;
}

.context-bar label {
    font-size: 13px;
}

.context-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 14px;
    font-weight: 700;
}

.context-actions form {
    margin: 0;
}

.container {
    width: min(1040px, 100%);
    margin: 0 auto;
    padding: 20px;
}

.page-head {
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.home-head {
    margin-bottom: 10px;
}

.home-head h1 {
    margin-bottom: 4px;
    font-size: 30px;
}

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

.page-head p,
.empty,
small {
    color: var(--muted);
}

.button,
button,
input,
select,
textarea {
    min-height: 44px;
    border-radius: 8px;
    font: inherit;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    touch-action: manipulation;
}

.button.primary,
button.primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.success {
    border-color: var(--success);
    background: var(--success);
    color: #fff;
}

.warning {
    border-color: var(--warning);
    background: var(--warning);
    color: #fff;
}

.danger {
    border-color: var(--danger);
    background: var(--danger);
    color: #fff;
}

.messages {
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid #b8d6ff;
    background: #eef6ff;
    border-radius: 8px;
}

.messages p {
    margin: 4px 0;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.stat,
.panel,
.form-panel,
.done {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.stat span {
    display: block;
    font-size: 34px;
    font-weight: 800;
}

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

.panel-title,
.word-row,
.stat-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.word-list {
    display: grid;
    gap: 10px;
}

.word-row {
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.word-row div:first-child {
    display: grid;
    gap: 4px;
}

.word-row strong {
    font-size: 20px;
}

.word-row span {
    color: var(--text);
}

.row-actions,
.form-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.row-actions form {
    margin: 0;
}

.filters,
.form-panel {
    display: grid;
    gap: 12px;
    margin-bottom: 18px;
}

.filters {
    grid-template-columns: minmax(260px, 1fr) auto;
    align-items: end;
}

.words-head {
    align-items: end;
}

.words-head h1 {
    margin-bottom: 4px;
}

.words-head-actions,
.words-toolbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.words-toolbar {
    align-items: end;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.words-toolbar label {
    font-size: 13px;
    color: var(--muted);
}

.words-manager-list {
    gap: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
}

.word-manage-row {
    display: grid;
    grid-template-columns: minmax(260px, 1.5fr) minmax(170px, 0.8fr) minmax(110px, 0.5fr) auto;
    gap: 14px;
    align-items: center;
    padding: 12px 14px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
}

.word-manage-row:last-child {
    border-bottom: 0;
}

.word-main {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.word-main strong {
    font-size: 22px;
    line-height: 1.1;
}

.word-main span {
    color: var(--text);
    line-height: 1.4;
}

.word-meta,
.word-status {
    display: grid;
    gap: 5px;
    color: var(--muted);
}

.status-badge {
    justify-self: start;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
    line-height: 1.2;
}

.status-new {
    background: #eef3f8;
    color: #41546b;
}

.status-learning {
    background: #fff4d6;
    color: #825500;
}

.status-mastered {
    background: #e4f7ec;
    color: #11623a;
}

.status-difficult {
    background: #ffe5e2;
    color: #9d241e;
}

.word-actions {
    justify-content: end;
}

.word-actions .button {
    min-height: 36px;
    padding: 7px 10px;
    font-size: 14px;
}

label {
    display: grid;
    gap: 6px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    padding: 10px 12px;
    background: #fff;
}

.field-list {
    margin-bottom: 0;
    color: var(--muted);
}

.study-shell {
    display: grid;
    gap: 14px;
    max-width: 620px;
    margin: 0 auto;
}

.study-meta {
    color: var(--muted);
    text-align: center;
}

.study-home-link {
    justify-self: end;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--muted);
    font-size: 14px;
    font-weight: 800;
}

.study-progress {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.study-progress span {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--muted);
    font-size: 14px;
    font-weight: 800;
    text-align: center;
}

.card {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    width: 100%;
    border: 1px solid #b7cdfd;
    background:
        linear-gradient(180deg, rgba(255,255,255,0.94), rgba(255,255,255,0.98)),
        radial-gradient(circle at top left, #dce9ff, transparent 46%),
        #fff;
    box-shadow: 0 16px 40px rgba(36, 107, 254, 0.12);
    cursor: pointer;
    text-align: center;
    padding: 24px;
}

.card:focus {
    outline: 3px solid #9fc2ff;
    outline-offset: 2px;
}

.card-front {
    display: grid;
    gap: 14px;
    width: 100%;
}

.card-front strong {
    font-size: 56px;
    line-height: 1.05;
    color: #17315f;
}

.card-front em {
    color: var(--muted);
    font-style: normal;
}

.front-example {
    width: min(440px, 100%);
    margin: 0 auto;
    padding: 14px 16px;
    border-left: 4px solid var(--primary);
    background: var(--primary-soft);
    border-radius: 8px;
    color: #24364f;
    font-size: 20px;
    line-height: 1.45;
    text-align: left;
    display: block;
    min-height: 0;
}

button.front-example {
    border-top: 0;
    border-right: 0;
    border-bottom: 0;
    justify-content: flex-start;
}

.muted-example {
    color: var(--muted);
    border-left-color: #d7dfec;
    background: #f5f7fb;
}

.front-annotation {
    width: min(440px, 100%);
    margin: 0 auto;
    padding: 10px 14px;
    background: #fff8df;
    border: 1px solid #ecd27f;
    border-radius: 8px;
    color: #4b3b12;
    font-size: 18px;
    line-height: 1.45;
    text-align: left;
}

.front-annotation span {
    display: block;
    margin-bottom: 4px;
    color: #7a5c00;
    font-size: 13px;
    font-weight: 800;
}

.sentence-line {
    display: block;
    min-height: 0;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: 18px;
    line-height: 1.45;
    text-align: left;
    justify-content: flex-start;
}

.audio-main {
    width: 100%;
    min-height: 54px;
    font-weight: 800;
}

.speech-autoplay-unlock {
    border-color: #8fb2ff;
    background: var(--primary-soft);
    color: #17315f;
    font-weight: 800;
}

.speech-autoplay-unlock[hidden] {
    display: none;
}

.speech-repeat-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.speech-repeat-control select {
    min-height: 38px;
}

.card-back {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
}

.phonetic {
    color: var(--primary);
    font-size: 20px;
}

.meaning {
    font-size: 24px;
    font-weight: 700;
}

blockquote {
    margin: 0;
    padding-left: 14px;
    border-left: 4px solid var(--line);
}

blockquote footer {
    color: var(--muted);
}

.study-actions {
    display: grid;
    gap: 8px;
}

.study-actions button {
    min-height: 44px;
    font-weight: 800;
}

.review-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.review-actions button {
    padding: 8px 6px;
    font-size: 15px;
    white-space: normal;
}

.next-action {
    justify-self: center;
    min-width: 120px;
}

.two-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}

.home-context {
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
    padding: 12px;
}

.home-context form {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr) auto;
    gap: 10px;
    align-items: end;
}

.daily-limit-form {
    display: grid;
    grid-template-columns: minmax(160px, 220px) auto 1fr;
    gap: 10px;
    align-items: end;
}

.daily-limit-form small {
    align-self: center;
}

.home-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.home-actions .button {
    min-height: 38px;
    padding: 8px 12px;
}

.home-stats {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.home-stats .stat {
    padding: 10px;
}

.home-stats .stat span {
    font-size: 26px;
    line-height: 1;
}

.home-stats .stat strong {
    display: block;
    margin-top: 5px;
    font-size: 13px;
}

.recent-panel {
    padding: 12px;
}

.recent-panel .panel-title {
    margin-bottom: 8px;
}

.recent-panel h2 {
    margin-bottom: 0;
    font-size: 20px;
}

.recent-panel .word-list {
    gap: 0;
}

.recent-panel .word-row {
    padding: 10px 2px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
}

.recent-panel .word-row:last-child {
    border-bottom: 0;
}

.recent-panel .word-row strong {
    font-size: 17px;
}

.search-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 16px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.search-links,
.keyword-list {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.keyword-list a {
    padding: 8px 10px;
    background: #f1f5f9;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-weight: 700;
}

.stat-line {
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

@media (max-width: 760px) {
    body {
        background: #f8fafc;
    }

    .topbar,
    .context-bar,
    .page-head,
    .word-row {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar {
        position: static;
        gap: 10px;
        padding: 12px 14px;
    }

    .brand {
        font-size: 18px;
    }

    .topbar nav {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 6px;
        width: 100%;
        font-size: 13px;
    }

    .topbar nav a {
        min-height: 38px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: var(--surface);
    }

    .context-bar {
        padding: 10px 14px;
    }

    .context-actions {
        gap: 8px;
    }

    .stats-grid,
    .context-bar form,
    .search-panel,
    .home-context form,
    .daily-limit-form,
    .filters,
    .two-columns {
        grid-template-columns: 1fr;
    }

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

    .stat {
        padding: 12px;
    }

    .stat span {
        font-size: 28px;
    }

    .study-shell {
        max-width: none;
        gap: 12px;
    }

    .study-page .topbar,
    .study-page .context-bar {
        display: none;
    }

    .study-page .container {
        min-height: 100svh;
        padding: 8px 10px calc(14px + env(safe-area-inset-bottom));
    }

    .study-page .messages {
        margin-bottom: 8px;
    }

    .study-page .study-shell {
        align-content: start;
    }

    .study-page .study-home-link {
        position: fixed;
        top: calc(8px + env(safe-area-inset-top));
        right: 10px;
        z-index: 20;
        box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    }

    .study-meta {
        font-size: 13px;
        line-height: 1.45;
    }

    .study-page .study-meta {
        order: 20;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .study-page .study-progress {
        order: 21;
    }

    .card {
        min-height: min(420px, 44vh);
        padding: 18px;
        border-radius: 12px;
    }

    .study-page .card {
        min-height: min(460px, 48svh);
        margin-top: 0;
    }

    .card-back {
        padding: 16px;
        border-radius: 12px;
    }

    .meaning {
        font-size: 22px;
    }

    .audio-main {
        min-height: 58px;
        font-size: 18px;
    }

    .speech-repeat-control {
        justify-content: space-between;
        padding: 10px 12px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: var(--surface);
    }

    .review-actions {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .review-actions button {
        min-height: 54px;
        padding: 8px 5px;
        font-size: 13px;
    }

    .container {
        padding: 14px 12px calc(18px + env(safe-area-inset-bottom));
    }

    .card-front strong {
        font-size: clamp(40px, 14vw, 58px);
    }

    .front-example {
        font-size: 17px;
    }

    .front-annotation {
        font-size: 17px;
    }

    .next-action {
        width: 100%;
        min-height: 52px;
    }

    .word-row {
        gap: 10px;
    }

    .words-head-actions,
    .words-toolbar-actions {
        width: 100%;
    }

    .words-head-actions .button,
    .words-toolbar-actions .button {
        flex: 1;
    }

    .word-manage-row {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 12px;
    }

    .word-main strong {
        font-size: 21px;
    }

    .word-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 6px 10px;
    }

    .word-status {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .word-actions {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }

    .word-actions form {
        display: grid;
    }
}

@media (max-width: 420px) {
    .topbar nav {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .review-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (display-mode: standalone) {
    .topbar {
        padding-top: calc(12px + env(safe-area-inset-top));
    }
}
