:root {
    --paper: #f6f0e5;
    --ink: #202927;
    --muted: #77807a;
    --line: #d8d3c8;
    --card: #fffdf9;
    --coral: #e66e51;
    --darkcoral: #b94e39;
    --sage: #879f89;
    --pale: #e5eee3;
    --wrong: #f5dfd7;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--paper);
    font-family: Manrope, sans-serif;
    min-height: 100vh;
}

body:before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0.32;
    background-image: radial-gradient(
        #c8c1b4 0.7px,
        transparent 0.7px
    );
    background-size: 15px 15px;
    mask-image: linear-gradient(#000, transparent 68%);
}

button {
    font: inherit;
}

.shell {
    width: min(1120px, calc(100% - 48px));
    margin: auto;
    position: relative;
}

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

.topbar {
    position: relative;
    min-height: 70px;
    display: grid;
    grid-template-columns: minmax(200px, 1fr) auto minmax(200px, 1fr);
    align-items: center;
    padding: 10px 0 10px;
}

.brand {
    grid-column: 1;
    justify-self: start;
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 0 2px;
    color: var(--ink);
    text-decoration: none;
}

.gairaigo-help {
    grid-column: 2;
    position: relative;
    justify-self: center;
}

.gairaigo-help-button {
    height: 58px;
    font-size: 18px;
    display: flex;
    align-items: center;
    padding: 0 18px;
    border: 1px solid var(--line);
    background: var(--paper);
    color: var(--muted);
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.gairaigo-help-button:hover {
    color: var(--darkcoral);
    border-color: var(--coral);
    background: var(--card);
}

.gairaigo-help-panel {
    position: absolute;
    top: calc(100% + 10px);
    left: 50%;
    width: min(485px, calc(100vw - 80px));
    transform: translateX(-50%);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    background: var(--card);
    border: 1px solid var(--line);
    box-shadow: 0 12px 50px rgba(53, 45, 31, 0.12);
    padding: 16px 20px;
    color: var(--ink);
    font: 16px Manrope, sans-serif;
    line-height: 1.55;
    z-index: 3;
}

.gairaigo-help.is-open .gairaigo-help-panel {
    opacity: 1;
    visibility: visible;
}

@media (hover: hover) {
    .gairaigo-help:hover .gairaigo-help-panel {
        opacity: 1;
        visibility: visible;
    }
}

.gairaigo-help-panel p {
    margin: 0 0 10px;
}

.gairaigo-help-panel p:last-child {
    margin-bottom: 0;
}

.gairaigo-help-panel strong {
    color: var(--darkcoral);
}

.gairaigo-help-panel .example {
    color: var(--coral);
    font-weight: 700;
}

.mark {
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    color: var(--paper);
    background: var(--ink);
    font: 40px serif;
    transform: rotate(-4deg);
}

.brand strong,
.brand em {
    display: block;
    line-height: 1;
}

.brand strong {
    font-size: 30px;
    letter-spacing: -0.04em;
    margin-left: -0.5px;
}

.brand em {
    color: var(--darkcoral);
    font-size: 24px;
    font-style: normal;
    font-weight: 700;
    text-transform: uppercase;
    margin-top: 4px;
}

.card {
    background: var(--card);
    border: 1px solid #e3ded4;
    padding: 10px 42px 12px;
    box-shadow: 0 18px 55px rgba(53, 45, 31, 0.08);
    animation: rise 0.55s ease both;
}

.card-head {
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 18px;
}

.card-head .progress {
    width: 255px;
    justify-self: start;
}

.card-head button {
    border: 0;
    background: none;
    color: var(--muted);
    font-size: 18px;
    cursor: pointer;
}

.card-head button:hover {
    color: var(--darkcoral);
}

.card-head button:disabled {
    color: var(--line);
    cursor: default;
}

.progress {
    width: 255px;
}

.progress small {
    display: block;
    color: var(--muted);
    margin-bottom: 5px;
    font: 11px 'DM Mono', monospace;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.progress > div {
    height: 4px;
    background: #ddd8cd;
    overflow: hidden;
}

.progress b {
    display: block;
    width: 0;
    height: 100%;
    background: var(--coral);
    transition: width 0.4s;
}

.score-panel {
    min-width: 110px;
    min-height: 34px;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 18px;
}

.score-panel #score {
    color: var(--ink);
    font-weight: 700;
    font-size: 18px;
}

.card-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 50px;
}

.toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 18px;
    cursor: pointer;
}

.toggle input {
    accent-color: var(--darkcoral);
    cursor: pointer;
}

.toggle:hover {
    color: var(--darkcoral);
}

.term {
    text-align: center;
    padding: 25px 15px 19px;
}

.term div {
    width: 100%;
    font-size: clamp(35px, 8vw, 60px);
    line-height: 1.13;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.term p {
    width: 100%;
    font-size: 56px;
    font-weight: 600;
    color: var(--darkcoral);
    margin: 15px 0 0;
    white-space: nowrap;
}

.rule {
    display: flex;
    align-items: center;
    gap: 15px;
    color: var(--muted);
    margin-bottom: 17px;
}

.rule:before,
.rule:after {
    content: '';
    height: 1px;
    background: var(--line);
    flex: 1;
}

.rule span {
    font-size: 15px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}

.answers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 11px;
}

.answer {
    min-height: 72px;
    display: flex;
    align-items: center;
    gap: 16px;
    text-align: left;
    border: 1px solid var(--line);
    background: #fffefa;
    color: var(--ink);
    padding: 16px 18px;
    cursor: pointer;
    transition: 0.18s;
}

.answer:hover:not(:disabled) {
    border-color: var(--coral);
    background: #fff8f3;
    transform: translateY(-2px);
}

.letter {
    flex: 0 0 27px;
    height: 27px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    color: var(--muted);
    font: 11px 'DM Mono', monospace;
}

.answer-text {
    font-size: 23px;
    line-height: 1.4;
}

.answer.correct {
    border-color: var(--sage);
    background: var(--pale);
}

.answer.correct .letter {
    background: var(--sage);
    border-color: var(--sage);
    color: white;
}

.answer.wrong {
    border-color: var(--coral);
    background: var(--wrong);
}

.answer.wrong .letter {
    background: var(--coral);
    border-color: var(--coral);
    color: white;
}

.answer.dim {
    opacity: 0.5;
}

.answer:disabled {
    cursor: default;
}

.feedback {
    min-height: 77px;
    text-align: center;
    padding: 2px 0 2px;
    font-size: 25px;
    font-weight: 700;
}

.feedback.good {
    color: #58775c;
}

.feedback.bad {
    color: var(--darkcoral);
}

.origin {
    display: block;
    color: var(--ink);
    font-size: 25px;
    font-weight: 500;
    margin-top: 5px;
}

.next {
    display: block;
    margin: 7px auto 0;
    border: 0;
    color: white;
    background: var(--ink);
    padding: 13px 22px;
    font-size: 22px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.18s;
}

.next:hover:not(:disabled) {
    background: var(--darkcoral);
}

.next:disabled {
    opacity: 0.25;
    cursor: default;
}

.feedback-section {
    margin-top: 16px;
    text-align: center;
}

#feedback-button {
    border: 0;
    background: none;
    color: var(--muted);
    padding: 4px 8px;
    font-size: 16px;
    cursor: pointer;
}

#feedback-button:hover {
    color: var(--darkcoral);
    text-decoration: underline;
}

.feedback-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(32, 41, 39, 0.45);
    z-index: 10;
}

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

.feedback-dialog {
    width: min(500px, 100%);
    padding: 24px;
    background: var(--card);
    border: 1px solid var(--line);
    box-shadow: 0 18px 55px rgba(53, 45, 31, 0.2);
}

.feedback-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.feedback-header h2 {
    margin: 0;
    font: 500 28px Fraunces, Georgia, serif;
}

.feedback-close {
    border: 0;
    background: none;
    color: var(--muted);
    padding: 2px 6px;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

.feedback-close:hover {
    color: var(--darkcoral);
}

#feedback-form {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

#feedback-form label {
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

#feedback-form select,
#feedback-form textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 0;
    background: #fffefa;
    color: var(--ink);
    padding: 10px 12px;
    font: 16px Manrope, sans-serif;
}

#feedback-form select:focus,
#feedback-form textarea:focus {
    outline: none;
    border-color: var(--coral);
}

#feedback-form textarea {
    min-height: 120px;
    resize: vertical;
}

#feedback-form > button {
    align-self: center;
    margin-top: 6px;
    border: 0;
    color: white;
    background: var(--ink);
    padding: 11px 20px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.18s;
}

#feedback-form > button:hover {
    background: var(--darkcoral);
}

.feedback-status {
    min-height: 1.4em;
    margin: 6px 0 0;
    text-align: center;
    color: var(--ink);
    font-size: 18px;
}

footer {
    color: var(--muted);
    font-size: 14px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding-top: 24px;
    padding-bottom: 24px;
}

footer span:last-child {
    color: #a49e91;
    display: flex;
    gap: 26px;
    align-items: center;
}

footer a {
    color: var(--muted);
    text-decoration: underline;
    text-underline-offset: 3px;
}

footer a:hover {
    color: var(--darkcoral);
}

footer .footer-separator {
    color: #a49e91;
}

.page-card {
    padding: 28px 42px 36px;
}

.page-title {
    border-bottom: 1px solid var(--line);
    padding-bottom: 16px;
    margin-bottom: 16px;
}

.page-title h1 {
    margin: 0;
    color: var(--ink);
    font-size: clamp(34px, 5vw, 44px);
    line-height: 1.2;
    letter-spacing: -0.03em;
}

.page-content {
    color: var(--ink);
}

.page-section {
    margin: 0 0 22px;
}

.page-section h2 {
    color: var(--darkcoral);
    font-size: 20px;
    margin: 0 0 10px;
}

.page-section p {
    margin: 0 0 12px;
    line-height: 1.7;
    font-size: 16px;
}

.page-section em {
    font-style: italic;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 700px) {
    .shell {
        width: min(calc(100% - 28px), 560px);
        padding-top: 18px;
    }

    .topbar {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 6px;
        padding-bottom: 17px;
    }

    .gairaigo-help-button {
        padding-right: 10px;
        padding-left: 10px;
    }

    .gairaigo-help-panel {
        right: 0;
        left: auto;
        width: min(485px, calc(100vw - 32px));
        transform: none;
    }

    .card-head .progress {
        width: 90%;
        min-width: 0;
        padding: 0;
        margin-right: 0;
        transform: translateY(-10px);
    }

    .card-head .progress small {
        font-size: 12px;
    }

    .card-head {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0;
        justify-items: center;
        padding-bottom: 0;
    }

    .card-head .card-actions {
        display: contents;
    }

    .card-head .score-panel {
        grid-column: auto;
        min-width: 0;
        gap: 2px;
        font-size: 14px;
        white-space: nowrap;
        transform: translate(8px, -10px);
    }

    .card-head .score-panel #score {
        font-size: 14px;
    }

    .card-head .toggle {
        width: 100%;
        gap: 3px;
        font-size: 14px;
        justify-content: center;
        transform: translate(19px, -10px);
    }

    .card-head .toggle input {
        margin: 0;
        flex: 0 0 auto;
    }

    .card-head button {
        grid-column: auto;
        font-size: 14px;
        white-space: nowrap;
        transform: translate(19px, -10px);
    }

    .card {
        padding: 20px 17px 25px;
    }

    .term {
        padding: 14px 3px 10px;
    }

    .term p {
        font-size: clamp(26px, 9vw, 40px);
        margin-top: 4px;
    }

    .term div {
        font-size: clamp(37px, 14vw, 70px);
    }

    .answers {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .answer {
        min-height: 62px;
        padding: 13px 14px;
    }

    .answer-stats {
        margin-left: 0.5rem;
        opacity: 0.65;
        font-size: 0.85em;
        font-weight: 600;
    }

    .feedback-dialog {
        padding: 20px;
    }

    footer {
        flex-direction: column;
        gap: 8px;
        line-height: 1.6;
        text-align: center;
    }

    footer span:last-child {
        order: -1;
        justify-content: center;
        gap: 12px;
        flex-wrap: wrap;
    }
}

@media (max-width: 360px) {
    .topbar {
        grid-template-columns: 1fr;
        justify-items: center;
        gap: 10px;
    }

    .brand,
    .gairaigo-help {
        grid-column: 1;
    }
}

@media (max-width: 280px) {
    .card-head .progress small {
        font-size: 10px;
    }

    .card-head .score-panel,
    .card-head .score-panel #score,
    .card-head .toggle,
    .card-head button {
        font-size: 11px;
    }

    .card-head .score-panel,
    .card-head .toggle {
        transform: translateX(1px);
    }

    .card-head .toggle {
        font-size: 10px;
        transform: translateX(0.5px);
    }

    .card-head .toggle input {
        width: 11px;
    }
}
