:root {
  --ink: #16283a;
  --ink-soft: #29435a;
  --paper: #f7f1e3;
  --paper-deep: #ecdfc4;
  --red: #c94135;
  --red-dark: #9d2d25;
  --gold: #e4b857;
  --green: #2c7a62;
  --white: #fffdf7;
  --muted: #6d746f;
  --shadow: 0 14px 35px rgba(27, 38, 47, .12);
}
* { box-sizing: border-box; }
html { background: var(--paper); color: var(--ink); font-family: "Hiragino Sans", "Yu Gothic", system-ui, sans-serif; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 90% 0, rgba(228,184,87,.2), transparent 28rem), linear-gradient(180deg, #fbf7ec 0%, var(--paper) 100%); }
button { font: inherit; }
.topbar { min-height: 78px; padding: 14px max(18px, env(safe-area-inset-left)); display: flex; align-items: center; gap: 12px; color: white; background: var(--ink); border-bottom: 4px solid var(--gold); }
.brand-mark { display: grid; place-items: center; width: 47px; height: 47px; flex: 0 0 auto; border: 2px solid var(--gold); transform: rotate(45deg); color: var(--gold); font-family: serif; font-size: 25px; font-weight: 800; }
.brand-mark::first-letter { transform: rotate(-45deg); }
.topbar h1 { margin: 1px 0 0; font-family: serif; font-size: clamp(1.25rem, 5vw, 1.65rem); letter-spacing: .08em; }
.eyebrow { margin: 0; color: #d8c998; font-size: .72rem; letter-spacing: .16em; }
.header-actions { display: flex; gap: 7px; margin-left: auto; }
.icon-button { padding: 9px 11px; color: white; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.25); border-radius: 10px; font-size: .76rem; font-weight: 700; cursor: pointer; }
.sync-button.connected { color: var(--ink); background: var(--gold); border-color: var(--gold); }
main { width: min(100%, 760px); margin: 0 auto; padding: 18px 16px 44px; }
.status-strip { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 16px; background: var(--white); border: 1px solid #e4d9c1; border-radius: 16px; box-shadow: 0 6px 20px rgba(37,47,55,.07); }
.status-strip div { padding: 12px 6px; text-align: center; border-right: 1px solid #e8dfcd; }
.status-strip div:last-child { border-right: 0; }
.status-strip strong { display: inline-block; margin: 0 4px; font-size: 1.25rem; }
.status-strip small { color: var(--muted); font-weight: 700; }
.status-strip .best-streak { display: block; margin-top: 3px; color: var(--red-dark); font-size: .68rem; }
.status-strip .best-streak span { font-weight: 900; }
.status-icon { font-size: .9rem; color: var(--red); font-weight: 900; }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 22px; padding: 5px; background: #dfd4bf; border-radius: 13px; }
.tab { min-height: 44px; border: 0; border-radius: 9px; background: transparent; color: #5e625f; font-size: .88rem; font-weight: 800; cursor: pointer; }
.tab.active { background: var(--white); color: var(--ink); box-shadow: 0 2px 9px rgba(30,40,50,.12); }
.view { display: none; }
.view.active { display: block; animation: rise .28s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(5px); } }
.date-row, .section-title { display: flex; align-items: end; justify-content: space-between; margin-bottom: 14px; }
h2 { margin: 2px 0 0; font-family: serif; font-size: 1.55rem; }
.muted { margin: 0; color: var(--muted); font-size: .83rem; font-weight: 650; }
.daily-badge, #unifyPercent { padding: 6px 10px; color: var(--red-dark); background: #f5ded5; border-radius: 99px; font-size: .84rem; font-weight: 900; }
.ai-notice { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; padding: 13px 14px; background: #fff8dc; border: 1px solid #dccb8d; border-radius: 13px; }
.ai-notice.hidden { display: none; }
.ai-notice strong { font-size: .84rem; }
.ai-notice p { margin: 3px 0 0; color: #5f5b4e; font-size: .78rem; line-height: 1.55; }
.ai-notice button { flex: 0 0 auto; padding: 8px 10px; color: var(--ink-soft); background: white; border: 1px solid #cabd8c; border-radius: 9px; font-size: .74rem; font-weight: 800; cursor: pointer; }
.mission-card { position: relative; overflow: hidden; margin-bottom: 14px; padding: 20px; border-radius: 18px; box-shadow: var(--shadow); }
.mission-card::after { content: ""; position: absolute; width: 110px; height: 110px; right: -28px; top: -35px; border: 18px double rgba(255,255,255,.1); border-radius: 50%; }
.mission-card.primary { color: white; background: linear-gradient(135deg, var(--red-dark), var(--red)); }
.mission-card.challenge { color: white; background: linear-gradient(135deg, #1b354a, #315b73); }
.mission-card.mania { color: white; background: linear-gradient(135deg, #38304d, #65516e); }
.mission-heading { position: relative; z-index: 1; display: flex; align-items: center; gap: 9px; }
.level, .category { display: inline-flex; align-items: center; min-height: 26px; padding: 4px 9px; border-radius: 99px; font-size: .76rem; font-weight: 900; }
.mission-card .level { color: var(--ink); background: var(--gold); }
.mission-card .category { color: white; border: 1px solid rgba(255,255,255,.4); }
.mission-card h3 { position: relative; z-index: 1; margin: 13px 0 6px; font-size: 1.3rem; }
.mission-card p { position: relative; z-index: 1; margin: 0 0 18px; color: rgba(255,255,255,.83); line-height: 1.65; }
.main-button, .secondary-button { position: relative; z-index: 1; min-height: 48px; padding: 0 20px; border: 0; border-radius: 12px; font-weight: 900; cursor: pointer; }
.main-button { color: white; background: var(--red); box-shadow: 0 5px 0 var(--red-dark); }
.mission-card .main-button { color: var(--red-dark); background: white; box-shadow: 0 5px 0 rgba(89,16,12,.35); }
.secondary-button { color: var(--ink); background: var(--gold); box-shadow: 0 5px 0 #a77d2d; }
.main-button:active, .secondary-button:active { transform: translateY(3px); box-shadow: none; }
.full { width: 100%; }
.text-button { display: block; margin: 20px auto 0; padding: 10px; color: var(--ink-soft); background: transparent; border: 0; font-weight: 800; cursor: pointer; }
.progress-track { height: 11px; overflow: hidden; margin-bottom: 20px; background: #ded2bb; border-radius: 99px; }
.progress-track span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--red), var(--gold)); transition: width .4s ease; }
.territory-grid { display: grid; gap: 18px; }
.region-group { padding: 14px; background: rgba(255,255,255,.46); border: 1px solid #e0d4bd; border-radius: 17px; }
.region-group h3 { margin: 0 0 11px; color: var(--red-dark); font-family: serif; font-size: 1.05rem; letter-spacing: .08em; }
.region-lands { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.territory { min-height: 96px; padding: 12px; background: rgba(255,255,255,.74); border: 1px solid #dfd3bc; border-radius: 15px; }
.territory.learned { width: 100%; color: var(--ink); text-align: left; cursor: pointer; box-shadow: 0 3px 10px rgba(30,40,50,.08); }
.territory.learned:active { transform: translateY(2px); }
.territory.learned.selected { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(228,184,87,.25); }
.territory.locked { color: #92928d; background: rgba(228,222,208,.48); filter: grayscale(1); }
.territory span { display: block; font-size: 1.65rem; }
.territory strong { display: block; margin-top: 6px; }
.territory small { color: var(--muted); }
.note { margin-top: 15px; color: var(--muted); font-size: .83rem; text-align: center; }
.region-exam-card { margin-bottom: 18px; padding: 20px; background: #fff9eb; border: 2px solid var(--gold); border-radius: 16px; box-shadow: var(--shadow); }
.region-exam-card.hidden { display: none; }
.region-exam-card span { color: var(--red-dark); font-size: .88rem; font-weight: 900; }
.region-exam-card h3 { margin: 7px 0; font-family: serif; font-size: 1.3rem; }
.region-exam-card p { margin: 0 0 14px; line-height: 1.6; }
.castle-knowledge { position: fixed; width: min(92vw, 560px); max-height: min(82vh, 760px); overflow: auto; padding: 22px; color: white; background: linear-gradient(135deg,var(--ink),#294d66); border: 2px solid var(--gold); border-radius: 16px; box-shadow: 0 18px 65px rgba(0,0,0,.32); }
.castle-knowledge::backdrop { background: rgba(12,24,36,.65); }
.castle-knowledge span { color: #dbc98a; font-size: .78rem; font-weight: 800; }
.castle-knowledge h2 { margin: 6px 44px 7px 0; font-family: serif; font-size: 1.35rem; }
.castle-knowledge p { margin: 0; color: #edf1f2; line-height: 1.7; }
.castle-more { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; margin-top: 17px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.2); }
.castle-more h3 { margin: 0 0 8px; color: #f0d793; font-family: inherit; font-size: .88rem; }
.castle-more ul { margin: 0; padding-left: 1.15rem; line-height: 1.65; }
.castle-more li { margin-bottom: 3px; overflow-wrap: anywhere; }
.knowledge-item { width: 100%; padding: 7px 9px; border: 1px solid rgba(255,255,255,.35); border-radius: 8px; background: rgba(255,255,255,.08); color: white; font: inherit; text-align: left; cursor: pointer; }
.knowledge-item:hover, .knowledge-item:focus-visible { background: rgba(255,255,255,.2); outline-color: #f0d793; }
.knowledge-item.selected { border-color: #f0d793; background: rgba(240,215,147,.24); font-weight: 800; }
.knowledge-dialog { position: fixed; width: min(90vw, 480px); max-height: min(78vh, 720px); overflow: auto; padding: 26px 24px; border: 2px solid var(--gold); border-radius: 18px; color: var(--ink); background: var(--white); box-shadow: 0 18px 65px rgba(0,0,0,.32); }
.knowledge-dialog::backdrop { background: rgba(12,24,36,.7); }
.knowledge-dialog { width: min(86vw, 460px); }
.knowledge-dialog span { display: block; padding-right: 40px; color: var(--red-dark); font-weight: 900; font-size: .88rem; }
.knowledge-dialog h2 { margin: 10px 35px 12px 0; font-size: 1.55rem; }
.knowledge-dialog p { line-height: 1.75; }
.knowledge-dialog .knowledge-era-note { margin-bottom: 0; color: var(--muted); font-size: .82rem; }
.knowledge-close { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; border: 0; border-radius: 10px; color: var(--ink); background: #f0e5d3; font-size: 1.5rem; cursor: pointer; }
.knowledge-close:focus-visible { outline: 3px solid var(--red); }
.knowledge-back { width: 100%; min-height: 44px; margin-top: 16px; border: 1px solid #c3ad82; border-radius: 10px; color: var(--ink); background: #f0e5d3; font: inherit; font-weight: 800; cursor: pointer; }
.knowledge-back:focus-visible { outline: 3px solid var(--red); }
.sync-dialog { position: fixed; width: min(92vw, 500px); max-height: min(86vh, 760px); overflow: auto; padding: 26px 24px; border: 2px solid var(--gold); border-radius: 18px; color: var(--ink); background: var(--white); box-shadow: 0 18px 65px rgba(0,0,0,.32); }
.sync-dialog::backdrop { background: rgba(12,24,36,.72); }
.sync-dialog h2 { margin: 7px 42px 10px 0; font-size: 1.45rem; }
.sync-dialog p { line-height: 1.65; }
.sync-kicker { color: var(--red-dark); font-size: .82rem; font-weight: 900; }
.sync-dialog form { display: grid; gap: 8px; margin-top: 18px; }
.sync-dialog label { margin-top: 5px; font-size: .9rem; font-weight: 850; }
.sync-dialog input { width: 100%; min-height: 48px; padding: 10px 12px; border: 2px solid #d7cdb9; border-radius: 10px; color: var(--ink); background: white; font-size: 1rem; }
.sync-dialog input:focus { border-color: var(--gold); outline: 2px solid rgba(228,184,87,.25); }
.sync-note { margin: 5px 0 10px; color: var(--muted); font-size: .82rem; }
.sync-status { padding: 12px; color: #1d5d4b; background: #e6f3ed; border-radius: 10px; font-weight: 750; }
.sync-status.sync-status-error { color: #842d26; background: #f8e3df; }
.sync-error { margin-top: 14px; padding: 11px; color: #842d26; background: #f8e3df; border-radius: 10px; font-size: .88rem; font-weight: 750; }
.sync-disconnect { margin-top: 10px; color: var(--red-dark); }
.sync-dialog .hidden { display: none; }
.castle-knowledge .castle-era-note { margin-top: 12px; color: #c8d4dc; font-size: .78rem; }
@media(max-width:420px) { .castle-more { grid-template-columns: 1fr; } }
@media(max-width:500px) {
  .topbar { gap: 9px; }
  .brand-mark { width: 42px; height: 42px; font-size: 22px; }
  .topbar h1 { font-size: 1.12rem; }
  .eyebrow { font-size: .64rem; }
  .header-actions { flex-direction: column; gap: 4px; }
  .icon-button { min-height: 30px; padding: 4px 8px; font-size: .68rem; }
}
.weakness-card { margin-bottom: 18px; padding: 19px; color: white; background: var(--ink); border-left: 6px solid var(--gold); border-radius: 15px; }
.weakness-card span { display: block; color: #d9c98f; font-size: .76rem; font-weight: 800; }
.weakness-card strong { display: block; margin-top: 5px; font-size: 1.25rem; }
.weakness-card p { margin: 7px 0 0; color: #dce4e8; font-size: .88rem; line-height: 1.55; }
.category-list { margin-bottom: 18px; }
.category-row { display: grid; grid-template-columns: 70px 1fr 48px; align-items: center; gap: 9px; margin-bottom: 12px; }
.category-row strong { font-size: .87rem; }
.mini-track { height: 8px; overflow: hidden; background: #ded3bd; border-radius: 99px; }
.mini-track span { display: block; height: 100%; background: var(--green); border-radius: 99px; }
.category-row small { color: var(--muted); text-align: right; }
.quiz-view { padding-bottom: 30px; }
.back-button { margin-bottom: 15px; padding: 8px 0; color: var(--ink-soft); background: transparent; border: 0; font-weight: 800; }
.quiz-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 11px; }
.quiz-meta .level.easy { color: #176249; background: #d7eee4; }
.quiz-meta .level.standard { color: #6b4b00; background: #f3e2b4; }
.quiz-meta .level.hard { color: #8d2721; background: #f4d5d2; }
.quiz-meta .level.mania { color: #49345c; background: #e9dff1; }
.quiz-meta .category { color: var(--ink-soft); background: #e8e3d7; }
#quizCount { margin-left: auto; color: var(--muted); font-size: .8rem; }
.question-card { padding: clamp(20px, 5vw, 30px); background: var(--white); border: 1px solid #e2d6bf; border-top: 5px solid var(--ink); border-radius: 18px; box-shadow: var(--shadow); }
.question-kicker { margin: 0 0 7px; color: var(--red); font-size: .78rem; font-weight: 900; letter-spacing: .12em; }
.question-card h2 { margin: 0 0 24px; font-family: inherit; font-size: clamp(1.15rem, 4.7vw, 1.45rem); line-height: 1.65; }
rt { color: var(--muted); font-size: .55em; font-weight: 600; }
ruby { ruby-position: over; }
.choices { display: grid; gap: 11px; }
.choice { display: grid; grid-template-columns: 33px 1fr; align-items: center; min-height: 55px; padding: 9px 13px; color: var(--ink); text-align: left; background: white; border: 2px solid #d9d1c1; border-radius: 12px; cursor: pointer; }
.choice b { display: grid; place-items: center; width: 27px; height: 27px; color: var(--ink-soft); background: #ece6da; border-radius: 50%; }
.choice:hover { border-color: var(--gold); }
.choice.correct { border-color: var(--green); background: #e5f4ed; }
.choice.wrong { border-color: var(--red); background: #f8e3df; }
.choice:disabled { cursor: default; opacity: 1; }
.result-panel { margin-top: 14px; padding: 18px; background: var(--white); border: 1px solid #dfd3bc; border-radius: 16px; }
.result-panel.hidden { display: none; }
.result-title { display: flex; align-items: center; gap: 9px; color: var(--ink); font-size: 1.15rem; }
.result-panel p { line-height: 1.7; }
.memory-tip { padding: 11px 13px; background: #f1eadb; border-radius: 10px; font-size: .88rem; }
footer { padding: 24px; color: #77786f; font-size: .76rem; text-align: center; }
@media (min-width: 680px) {
  main { padding-top: 25px; }
  .region-lands { grid-template-columns: repeat(5, 1fr); }
  #dailyView { display: none; grid-template-columns: 1fr 1fr; gap: 16px; }
  #dailyView.active { display: grid; }
  #dailyView .date-row, #dailyView .ai-notice, #dailyView .text-button { grid-column: 1 / -1; }
  .mission-card { margin-bottom: 0; }
}
@media (max-width: 460px) { .ai-notice { align-items: flex-start; flex-direction: column; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; } }
