:root {
  --bg: #f6f4ef;
  --paper: #fff;
  --ink: #1d2729;
  --muted: #5b6668;
  --line: #d9d4c8;
  --accent: #0f766e;
  --accent-ink: #fff;
  --accent-soft: #e3f2ef;
  --me: #e6f3f0;
  --them: #fff;
  --ok: #157347;
  --ok-soft: #e4f4ea;
  --ng: #b42318;
  --ng-soft: #fdecea;
  --warn-soft: #fff4d6;
  --map-bg: #eef0e8;
  --map-road: #fff;
  --map-block: #dcdfd3;
  --map-park: #cfe3c4;
  --pin: #8a8f86;
  --pin-main: #c2410c;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1rem/1.65 system-ui, "Noto Sans SC", "Microsoft YaHei", sans-serif;
}
/* English / Vietnamese: fonts with full Vietnamese stacked diacritics (ế ắ ẫ ầ…) come
   first. system-ui must not lead: on Chinese-language Windows it resolves to
   Microsoft YaHei UI, which splits ế into ê + ´ (seen in the 390px QA capture). */
:lang(en), :lang(vi) { font-family: "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, system-ui, sans-serif; }
:lang(ja) { font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif; }
#app { width: min(100% - 2rem, 60rem); margin: 0 auto; padding: 1.25rem 0 3rem; outline: none; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
h1, h2, h3 { line-height: 1.35; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.45rem, 4.5vw, 2rem); }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
rt { font-size: .55em; color: var(--muted); }
.no-ruby rt { display: none; }
/* .tr = translation of the Japanese (hidden with 翻訳：非表示); interface words never hide */
.no-tr .tr, .no-tr .tr-inline { display: none; }
.h-tr { display: block; font-size: .8rem; font-weight: 500; color: var(--muted); }
.lead { color: var(--muted); max-width: 44rem; }
.fine { font-size: .82rem; color: var(--muted); }
.hint { font-size: .85rem; color: var(--muted); }

/* buttons */
.btn {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 48px; padding: .45rem 1rem; border: 1.5px solid var(--accent); border-radius: 999px;
  background: var(--paper); color: var(--accent); font-weight: 700; text-decoration: none; cursor: pointer; line-height: 1.25;
}
.btn small { font-weight: 500; font-size: .72rem; opacity: .85; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:hover:not(:disabled) { filter: brightness(.95); }
.toggles { display: flex; flex-wrap: wrap; gap: .5rem; }
.toggle {
  min-height: 40px; padding: .3rem .85rem; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--paper); cursor: pointer; font-size: .9rem;
}
.toggle[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.toggle[aria-pressed="true"]::before { content: "✓ "; }
.langs { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; }
.langs-label { font-size: .85rem; font-weight: 700; color: var(--muted); margin-right: .1rem; }
.toggle.lang { padding: .3rem .7rem; }
.say {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--paper); cursor: pointer; font-size: 1.05rem;
}
.chip {
  display: inline-flex; align-items: center; gap: .3rem; min-height: 36px; padding: .2rem .7rem; margin: .15rem;
  border: 1px solid var(--line); border-radius: 999px; background: var(--paper); font-size: .85rem;
}
button.chip { cursor: pointer; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.chips { margin: .25rem 0 .5rem; font-size: .85rem; color: var(--muted); }

/* home */
.hero { padding: .5rem 0 1rem; }
.kicker { color: var(--accent); font-weight: 700; margin-bottom: .25rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: center; margin-top: 1rem; }
.hero .toggles { margin-block-end: .75rem; }
.scene-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); gap: .65rem; align-items: start; }
.scene-group { min-inline-size: 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.scene-group h2 { font-size: 1rem; color: var(--accent); margin: 0; padding: .45rem .8rem; background: var(--accent-soft); border-start-start-radius: var(--radius); border-start-end-radius: var(--radius); }
.scene-list { list-style: none; margin: 0; padding: 0 .7rem; }
.scene-list li + li { border-block-start: 1px solid var(--line); }
.scene-entry { display: flex; align-items: center; gap: .55rem; min-block-size: 48px; padding: .3rem .1rem; color: inherit; text-decoration: none; }
.scene-entry .scene-icon { font-size: 1.25rem; flex: none; }
.scene-label { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 .4rem; min-inline-size: 0; }
.scene-label .jp { font-size: .91rem; }
.scene-arrow { margin-inline-start: auto; font-size: 1.25rem; color: var(--accent); }
.scene-entry:hover, .scene-entry:focus-visible { color: var(--accent); }
.card, .box, .step, .talk, .paper, .memo {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem;
}
.card { display: flex; flex-direction: column; }
.card-top { display: flex; gap: .75rem; align-items: flex-start; }
.card h2 a { color: inherit; text-decoration: none; }
.card h2 a:hover { text-decoration: underline; }
.card-sum { font-size: .92rem; margin-top: .5rem; }
.scene-icon { font-size: 1.9rem; line-height: 1; }
.dept { font-size: .85rem; color: var(--muted); margin: 0; }
.steps-mini { display: flex; flex-wrap: wrap; gap: .25rem; list-style: none; padding: 0; margin: .25rem 0 .75rem; font-size: .82rem; }
.steps-mini li { background: var(--bg); border-radius: 6px; padding: .1rem .45rem; }
.steps-mini li + li::before { content: "→ "; color: var(--muted); }
.card-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: auto; padding-top: .5rem; }
.card-actions .btn { flex: 1 1 8rem; }

.emergency {
  margin: 1.5rem 0 .75rem; padding: .75rem 1rem; border-left: 4px solid var(--ng); background: var(--ng-soft);
  border-radius: 8px; font-size: .9rem;
}
.emergency strong { color: var(--ng); margin-right: .25rem; }
.emergency a { display: inline-block; margin-left: .25rem; }

/* scene header */
.scene-head { margin-bottom: 1rem; }
.back { display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; font-size: .9rem; }
.scene-title { display: flex; gap: .75rem; align-items: center; margin-bottom: .75rem; }
.scene-title h1 { margin: 0; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: .25rem; background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: .25rem; }
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 48px;
  border-radius: 999px; text-decoration: none; color: var(--ink); font-size: .85rem; font-weight: 700; line-height: 1.2; text-align: center;
}
.tabs a small { font-weight: 500; font-size: .7rem; color: var(--muted); }
/* 「会話を練習する」 overflowed its pill at 390px: tighter type and inner padding on phones */
@media (max-width: 420px) {
  .tabs a { font-size: .74rem; padding: .2rem .3rem; }
  .tabs a small { font-size: .66rem; }
}
.tabs a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.tabs a[aria-current="page"] small { color: inherit; opacity: .85; }
.talk-tools { display: flex; justify-content: flex-end; margin-bottom: .75rem; }

.memo { background: var(--warn-soft); border-color: #ecd9a4; margin-bottom: 1rem; }
.memo h3 { font-size: .95rem; }
.memo ul { margin: 0; padding-left: 1.2rem; font-size: .92rem; }

/* prep */
.step { margin-bottom: 1rem; }
.step h2, .flow h2 { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem .5rem; }
.step h2 .h-tr, .flow h2 .h-tr { display: inline; }
.num {
  display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: .9rem; flex: none;
}
.mock { border: 1px dashed var(--muted); border-radius: 12px; padding: .75rem; background: #fbfbf8; }
.mock-tag { display: inline-block; font-size: .75rem; color: var(--muted); background: var(--bg); padding: 0 .5rem; border-radius: 4px; }
.searchbar { padding: .55rem .9rem; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); box-shadow: 0 1px 3px #0001; }
.map-svg svg { display: block; width: 100%; height: auto; border-radius: 10px; margin: .5rem 0; }
.results { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.result {
  display: flex; align-items: center; gap: .6rem; width: 100%; min-height: 56px; padding: .5rem .75rem; text-align: left;
  border: 1px solid var(--line); border-radius: 10px; background: var(--paper); cursor: pointer;
}
.result:disabled { cursor: default; opacity: .7; }
.result.main { border-color: var(--pin-main); }
.result > span:nth-child(2) { flex: 1; display: flex; flex-direction: column; }
.result small { color: var(--muted); }
.pin { display: grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--pin); color: #fff; font-weight: 700; font-size: .8rem; flex: none; }
.result.main .pin { background: var(--pin-main); }
.status { font-size: .8rem; font-weight: 700; white-space: nowrap; }
.status.open { color: var(--ok); }
.status.closed { color: var(--ng); }
.site-mock h3 { font-size: 1.15rem; margin-top: .25rem; }
.site-dept { color: var(--muted); font-size: .85rem; }
.site-mock table { width: 100%; border-collapse: collapse; margin: .25rem 0 .75rem; font-size: .9rem; }
.site-mock caption { text-align: left; font-weight: 700; padding-bottom: .25rem; }
.site-mock th, .site-mock td { border: 1px solid var(--line); padding: .35rem .5rem; text-align: left; }
.site-mock th { background: var(--bg); white-space: nowrap; width: 40%; }
.site-alert { background: var(--warn-soft); border-radius: 8px; padding: .5rem .75rem; font-weight: 700; }
.others { font-size: .88rem; color: var(--muted); }
.others li::marker { content: "※ "; }

/* flow */
.flow { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: .75rem; }
.flow > li { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.box { margin: 1rem 0; }

/* conversation */
.parts { list-style: none; display: flex; gap: .35rem; padding: 0; margin: 0 0 1rem; overflow-x: auto; scrollbar-width: thin; }
.parts button {
  display: flex; flex-direction: column; align-items: center; min-width: 4.6rem; min-height: 48px; padding: .3rem .6rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--paper); cursor: pointer; font-size: .85rem; line-height: 1.25; white-space: nowrap;
}
.parts button small { color: var(--muted); font-size: .7rem; }
.parts button.past { background: var(--ok-soft); border-color: #b6dcc4; }
.parts button[aria-current="step"] { border: 2px solid var(--accent); background: var(--accent-soft); font-weight: 700; }
.part-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .6rem; }
.part-title .h-tr { display: inline; }
.count { margin-left: auto; font-size: .8rem; color: var(--muted); font-weight: 500; }
.log { display: flex; flex-direction: column; gap: .7rem; margin: .75rem 0 1rem; }
.bubble {
  max-width: min(100%, 36rem); padding: .6rem .85rem .7rem; border-radius: 16px; border: 1px solid var(--line);
  background: var(--them); transition: box-shadow .2s;
}
.bubble.me { align-self: flex-end; background: var(--me); border-color: #b9ddd5; border-bottom-right-radius: 4px; }
.bubble.them { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.speaking, .review-list li.speaking, .alt p.speaking { box-shadow: 0 0 0 3px #f59e0b88; }
.bubble-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .1rem; }
.speaker { font-size: .8rem; font-weight: 700; color: var(--muted); }
.tr-inline { font-weight: 500; }
.line-ja { font-size: 1.15rem; line-height: 2; margin: 0; }
.bubble .tr { font-size: .9rem; color: var(--muted); margin: .1rem 0 0; }
.alt { margin-top: .5rem; padding-top: .4rem; border-top: 1px dashed #b9ddd5; font-size: .95rem; }
.alt small { color: var(--muted); }
.alt p { display: flex; flex-wrap: wrap; align-items: center; gap: .1rem .5rem; margin: .25rem 0 0; border-radius: 8px; }
.alt .say { width: 34px; height: 34px; font-size: .9rem; }
.shadow { font-size: .85rem; color: var(--accent); margin: .4rem 0 0; }
.form-link { font-size: .88rem; margin: .4rem 0 0; }
.controls { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: space-between; position: sticky; bottom: 0; padding: .6rem 0; background: linear-gradient(#fff0, var(--paper) 30%); }
.controls .btn { flex: 1 1 9rem; }

.task { align-self: stretch; padding: .85rem; border: 2px solid var(--accent); border-radius: 16px; background: var(--accent-soft); }
.task-ask { font-size: .95rem; }
.task-ask strong { color: var(--accent); }
.options { display: grid; gap: .5rem; }
.option {
  display: flex; flex-direction: column; align-items: flex-start; gap: .1rem; width: 100%; min-height: 52px; padding: .55rem .85rem;
  text-align: left; border: 1.5px solid var(--line); border-radius: 12px; background: var(--paper); cursor: pointer;
}
.option .jp { font-size: 1.05rem; line-height: 1.9; }
.option small { color: var(--muted); }
.option:hover:not(:disabled) { border-color: var(--accent); }
.option.wrong { border-color: var(--ng); background: var(--ng-soft); text-decoration: line-through; text-decoration-color: #b4231866; }
.option.right { border-color: var(--ok); background: var(--ok-soft); }
.feedback { font-size: .92rem; margin: .5rem 0 0; min-height: 0; }
.feedback:empty { display: none; }
.feedback.ng { color: var(--ng); }
.feedback.ok { color: var(--ok); }

/* eye test */
.eye-state { text-align: center; font-size: .88rem; margin-bottom: .5rem; }
.eyes { display: flex; justify-content: center; gap: 1.5rem; margin-bottom: .25rem; }
.eye { display: flex; flex-direction: column; align-items: center; min-width: 4.5rem; padding: .35rem .5rem; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); }
.eye.covered { background: #2b2b2b; color: #fff; border-color: #2b2b2b; }
.eye.covered rt { color: #ccc; }
.eye-icon { font-size: 1.5rem; line-height: 1.2; }
.eye small { font-size: .72rem; }
.ring-chart { display: grid; place-items: center; background: #fff; border-radius: 12px; border: 1px solid var(--line); padding: .75rem; margin: .5rem auto; width: min(100%, 14rem); }
.ring-chart svg { width: 100%; max-width: 9rem; height: auto; }
.ring-done { align-self: center; }
.ring-done .ring-chart { width: 6.5rem; padding: .3rem; margin: 0; }
.dirs { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.dir {
  display: flex; flex-direction: column; align-items: center; min-height: 56px; padding: .4rem; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--paper); cursor: pointer; font-size: 1.05rem; font-weight: 700;
}
.dir[data-dir="none"] { grid-column: 1 / -1; }
.dir kbd { font: .72rem/1 system-ui; color: var(--muted); margin-top: .15rem; }
.dir.wrong { border-color: var(--ng); background: var(--ng-soft); }
.dir:hover:not(:disabled) { border-color: var(--accent); }

/* body maps */
.bodymap-wrap { margin: .25rem 0; }
.bodymap svg { display: block; width: 100%; max-width: 20rem; height: auto; margin: 0 auto; touch-action: manipulation; }
.bodymap .body { fill: #f3dcc6; stroke: #b98d6c; stroke-width: 2; }
.bodymap .region { fill: #0f766e1f; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 3; cursor: pointer; }
.bodymap .region:hover { fill: #0f766e40; }
.bodymap .region.on { fill: #c2410c99; stroke: #c2410c; stroke-dasharray: none; }
.bodymap .mark { fill: #b98d6c; pointer-events: none; }
.bodymap .side { font-size: 13px; font-weight: 700; fill: var(--muted); }
.map-note { font-size: .8rem; color: var(--muted); text-align: center; margin: .25rem 0; }
.region-buttons { display: flex; flex-wrap: wrap; justify-content: center; }
.region-buttons small { font-size: .7rem; color: var(--muted); }
.picked { text-align: center; font-weight: 700; margin: .25rem 0 0; }

/* review */
.review h2 { outline: none; }
.review-list { list-style: none; padding: 0; display: grid; gap: .5rem; }
.review-list li { display: flex; gap: .6rem; align-items: flex-start; padding: .5rem .6rem; border-radius: 10px; background: var(--me); }
.review-list small { color: var(--muted); font-size: .75rem; }
.review-list .line-ja { font-size: 1.05rem; }
.review-list .tr { font-size: .88rem; color: var(--muted); margin: 0; }

/* practice form */
.paper { position: relative; margin-bottom: 1rem; background: #fffdf8; box-shadow: 0 1px 0 var(--line), 0 6px 18px #0000000d; }
.stamp {
  display: inline-block; margin-bottom: .5rem; padding: .15rem .75rem; border: 2px solid var(--ng); color: var(--ng);
  border-radius: 6px; font-weight: 800; letter-spacing: .05em; transform: rotate(-2deg);
}
.stamp small { font-weight: 600; letter-spacing: 0; }
.paper h2 { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .75rem; }
.paper h2 .h-tr { display: inline; }
.paper h2 .dept { margin-left: auto; }
.form-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; }
.field { display: block; border: 0; border-top: 1px solid var(--line); margin: 0; padding: .75rem 0; min-width: 0; }
.field legend { padding: 0; float: left; width: 100%; margin-bottom: .35rem; }
.field legend + * { clear: both; }
.f-label { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .5rem; font-weight: 700; margin-bottom: .35rem; }
.f-label small { font-weight: 500; color: var(--muted); font-size: .8rem; }
.f-input { display: flex; align-items: center; gap: .4rem; }
.field input[type="text"], .field input[type="time"] {
  width: 100%; min-height: 44px; padding: .45rem .7rem; font: inherit; font-size: 1rem;
  border: 1.5px solid var(--line); border-radius: 8px; background: #fff; color: inherit;
}
/* a time needs only a few characters; keep the picker compact next to its 今朝 label */
.field input[type="time"] { width: auto; min-width: 8.5rem; }
.field input[type="text"]:focus, .field input[type="time"]:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px #0f766e33; }
.suffix, .prefix { font-weight: 700; white-space: nowrap; }
.form-back { margin: .75rem 0 0; }
.f-options { display: flex; flex-wrap: wrap; gap: .4rem; }
.f-option {
  display: inline-flex; align-items: center; gap: .35rem; min-height: 44px; padding: .25rem .75rem .25rem .5rem;
  border: 1.5px solid var(--line); border-radius: 999px; background: #fff; cursor: pointer;
}
.f-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.f-option input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); margin: 0; }
.f-option small { font-size: .75rem; color: var(--muted); }
.field.sub { border-top: 0; padding: .5rem 0 0 1rem; }
.form-note { font-size: .88rem; background: var(--warn-soft); padding: .5rem .75rem; border-radius: 8px; margin: .75rem 0 0; }
.refs li { margin-bottom: .4rem; }
.refs small { display: block; color: var(--muted); }

@media (min-width: 640px) {
  #app { padding-top: 2rem; }
  .options { grid-template-columns: 1fr 1fr; }
  .dirs { grid-template-columns: repeat(5, 1fr); }
  .dir[data-dir="none"] { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
