/* 공부 친구 스타일. 아이가 폰으로 누르기 쉽게 크고 둥글게. */
:root {
    color-scheme: light;
    --bg: #fff8ef;
    --card: #ffffff;
    --ink: #2d2a32;
    --muted: #7a7480;
    --line: #f0e2d0;
    --accent: #ff8a3d;
    --accent-dark: #e86f1f;
    --ok: #1f9d55;
    --ok-bg: #e5f7ec;
    --ng: #d64545;
    --ng-bg: #fdeaea;
    --key: #fff1e3;
    --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
h1:focus { outline: none; }

/* ---------- 레이아웃 ---------- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
    padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
    background: var(--accent);
    color: #fff;
    text-align: center;
}
.app-title { font-size: 1.3rem; font-weight: 800; letter-spacing: 0.02em; }

.app-main {
    flex: 1;
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    padding: 16px 16px calc(24px + env(safe-area-inset-bottom, 0px));
}

/* ---------- 단원 선택 ---------- */
.hello { font-size: 1.6rem; margin: 8px 0 16px; text-align: center; }
.subject-tabs {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 6px;
    padding: 5px;
    background: var(--line);
    border-radius: var(--radius);
}
.subject-tabs button {
    min-height: 52px;
    border: none;
    border-radius: 14px;
    background: transparent;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--muted);
    white-space: nowrap;
}
.subject-tabs button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.06); }
.category-title { font-size: 1.1rem; margin: 22px 0 10px; color: var(--muted); }

.unit-grid { display: grid; gap: 12px; }

.unit-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: left;
    padding: 16px 18px;
    background: var(--card);
    border: 2px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 3px 0 var(--line);
    transition: transform 0.08s, border-color 0.08s;
}
.unit-card:hover { border-color: var(--accent); }
.unit-card:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.unit-name { font-size: 1.25rem; font-weight: 700; }
.unit-meta { color: var(--muted); }
.unit-last { color: var(--ok); font-weight: 600; }

/* ---------- 풀이 ---------- */
.quiz { display: flex; flex-direction: column; gap: 10px; }

.quiz-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.quiz-unit { font-weight: 700; color: var(--muted); text-align: right; }
.link-button {
    background: none;
    border: none;
    padding: 6px 0;
    color: var(--muted);
    font-size: 1rem;
}

.quiz-status { display: flex; justify-content: space-between; align-items: baseline; font-size: 1.15rem; }
.progress-text { font-weight: 800; font-size: 1.3rem; }
.quiz-controls { display: inline-flex; align-items: center; gap: 6px; }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); margin-right: 4px; }

/* 쓰기 / 키패드 전환 */
.mode-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    max-width: 420px;
    width: 100%;
    margin: 0 auto;
    background: var(--line);
    border-radius: 14px;
}
.mode-toggle button { min-height: 40px; border: none; border-radius: 10px; background: transparent; font-weight: 700; color: var(--muted); }
.mode-toggle button[aria-checked="true"] { background: var(--card); color: var(--ink); }

/* 손글씨 칸 */
.hw { max-width: 420px; width: 100%; margin: 0 auto; }
.hw-cells { display: flex; justify-content: center; gap: 10px; }
.hw-cell { position: relative; flex: 1 1 0; max-width: 180px; aspect-ratio: 1; }
.hw-canvas {
    --ink-color: var(--ink);
    display: block;
    width: 100%;
    height: 100%;
    background: var(--card);
    border: 3px dashed var(--accent);
    border-radius: var(--radius);
    touch-action: none; /* 쓸 때 화면이 스크롤되지 않게 */
    cursor: crosshair;
}
.hw.is-disabled .hw-canvas { opacity: 0.5; cursor: default; }
.hw-guess {
    position: absolute;
    right: 8px;
    top: 6px;
    min-width: 1.6em;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--ok);
    text-align: center;
    pointer-events: none;
}
.hw-guess.unsure { color: var(--accent-dark); }
.hw-guess.unsure::after { content: "?"; }
.hw-hint { min-height: 1.4em; margin: 6px 0 0; text-align: center; font-size: 0.9rem; color: var(--muted); }
.hw-hint .unsure { color: var(--accent-dark); font-weight: 700; }
.hw-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; max-width: 420px; width: 100%; margin: 0 auto; }
.ctl {
    width: 44px;
    height: 44px;
    border: 2px solid var(--line);
    border-radius: 12px;
    background: var(--card);
    font-size: 1.2rem;
    line-height: 1;
}
.ctl:disabled { opacity: 0.4; }

/* 일시정지 / 초기화 확인: 화면 전체를 덮어 문제를 가린다 */
.pause-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--bg);
}
.pause-card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    width: min(100%, 360px);
    padding: 24px 20px;
    background: var(--card);
    border: 3px solid var(--line);
    border-radius: var(--radius);
    text-align: center;
}
.pause-card h2 { margin: 0; font-size: 1.5rem; }
.pause-card p { margin: 0 0 4px; color: var(--muted); }
.pause-emoji { font-size: 3rem; line-height: 1; }

.progress-bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s; }

.question {
    display: flex;
    flex-wrap: nowrap;
    white-space: nowrap;
    align-items: center;
    justify-content: center;
    gap: 0.3em;
    margin-top: 8px;
    padding: 20px 12px;
    background: var(--card);
    border: 3px solid var(--line);
    border-radius: var(--radius);
    font-size: clamp(1.8rem, 9vw, 3.2rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    transition: background 0.15s, border-color 0.15s;
}
.question.is-ok { background: var(--ok-bg); border-color: var(--ok); }
.question.is-ng { background: var(--ng-bg); border-color: var(--ng); }
.question.text-q { flex-wrap: wrap; white-space: normal; }
.q-number { color: var(--muted); font-size: 0.6em; }

.answer-box {
    min-width: 2em;
    padding: 0 0.2em;
    border-bottom: 5px solid var(--accent);
    text-align: center;
    color: var(--accent-dark);
}

.feedback { min-height: 2.2rem; text-align: center; font-size: 1.5rem; font-weight: 800; }
.ok { color: var(--ok); }
.ng { color: var(--ng); }

.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-width: 420px;
    width: 100%;
    margin: 0 auto;
}

.key {
    min-height: 68px;
    font-size: 2rem;
    font-weight: 800;
    background: var(--key);
    border: 2px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 4px 0 var(--line);
    touch-action: manipulation;
    user-select: none;
}
.key:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.key:disabled { opacity: 0.5; }
.key-fn { color: var(--muted); }
.key-ok {
    background: var(--accent);
    border-color: var(--accent-dark);
    box-shadow: 0 4px 0 var(--accent-dark);
    color: #fff;
    font-size: 1.5rem;
}

.hint { margin: 4px 0 0; text-align: center; color: var(--muted); font-size: 0.9rem; }

.text-answer { display: flex; gap: 10px; }
.text-answer input {
    flex: 1;
    min-width: 0;
    font-size: 1.8rem;
    padding: 10px 14px;
    border: 3px solid var(--line);
    border-radius: var(--radius);
}
.text-answer input:focus { outline: none; border-color: var(--accent); }
.text-answer .key { padding: 0 20px; }

/* 폰에서는 키패드를 더 크게 */
@media (max-width: 480px) {
    .key { min-height: 72px; }
    .hint { display: none; }
}

/* ---------- 결과 ---------- */
.result-card {
    text-align: center;
    padding: 20px 16px;
    background: var(--card);
    border: 2px solid var(--line);
    border-radius: var(--radius);
}
.result-emoji { font-size: 3.5rem; line-height: 1; }
.result-score { margin: 8px 0 0; font-size: 2.6rem; color: var(--muted); }
.result-score b { color: var(--accent-dark); font-size: 1.3em; }
.result-message { font-size: 1.2rem; font-weight: 700; margin: 6px 0 12px; }
.result-stats { margin: 0; display: grid; gap: 6px; }
.result-stats div { display: flex; justify-content: center; gap: 10px; }
.result-stats dt { color: var(--muted); }
.result-stats dd { margin: 0; font-weight: 700; }

.wrong-title { font-size: 1.2rem; margin: 20px 0 8px; }
.wrong-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.wrong-list li {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 12px;
    padding: 12px 16px;
    background: var(--card);
    border: 2px solid var(--line);
    border-left: 6px solid var(--ng);
    border-radius: 12px;
}
.w-q { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.w-given { color: var(--ng); align-self: center; }

.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.big-button {
    min-height: 60px;
    font-size: 1.2rem;
    font-weight: 800;
    background: var(--card);
    border: 2px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 4px 0 var(--line);
}
.big-button.primary { background: var(--accent); border-color: var(--accent-dark); box-shadow: 0 4px 0 var(--accent-dark); color: #fff; }
.big-button:active { transform: translateY(3px); }

.card { background: var(--card); border-radius: var(--radius); padding: 20px; }
.center { text-align: center; }

/* ---------- 템플릿 기본 (로딩, 오류) ---------- */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}
.loading-progress circle {
    fill: none;
    stroke: #f0e2d0;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}
.loading-progress circle:last-child {
    stroke: var(--accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}
.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "불러오는 중"); }
