:root {
  --ink: #172321;
  --muted: #62706d;
  --paper: #f8f6ef;
  --surface: #fffdf8;
  --line: #dce2dc;
  --brand: #176b5b;
  --brand-dark: #0f4f43;
  --accent: #e6a83c;
  --soft: #e9f3ee;
  --danger: #a63d40;
  --warning: #fff2cf;
  --shadow: 0 12px 36px rgba(23, 35, 33, .08);
}

* { box-sizing: border-box; }
html { color-scheme: light; scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(230, 168, 60, .14), transparent 25rem),
    var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  line-height: 1.65;
}
button, input, textarea, select { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--brand-dark); text-underline-offset: .2em; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(1.05rem, 4.6vw, 1.35rem); line-height: 1.3; }
h2 { margin: .15rem 0 .65rem; font-size: clamp(1.45rem, 6vw, 2rem); line-height: 1.35; letter-spacing: -.02em; }
h3 { margin: 0 0 .55rem; line-height: 1.4; }
p { margin: .45rem 0 1rem; }
.hidden { display: none !important; }

.skip-link { position: fixed; left: .75rem; top: -5rem; z-index: 50; padding: .7rem 1rem; background: #fff; }
.skip-link:focus { top: .75rem; }
.app-header {
  position: sticky; top: 0; z-index: 10;
  max-width: 640px; margin: 0 auto; padding: .75rem 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: rgba(248, 246, 239, .94); backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(220, 226, 220, .75);
}
.eyebrow, .step-label { margin: 0 0 .25rem; color: var(--brand); font-weight: 800; font-size: .72rem; letter-spacing: .08em; }
.level-pill { min-width: 2.65rem; padding: .35rem .55rem; border-radius: 999px; color: #fff; background: var(--brand); text-align: center; font-weight: 900; }

main { max-width: 640px; min-height: calc(100vh - 150px); margin: 0 auto; padding: 1.25rem 1rem 7rem; }
.screen { display: none; animation: rise .28s ease; }
.screen.active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }

.hero-card, .theme-card, .settings-card, .candidate-card, .note-card, .tool-card, .success-panel {
  border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow);
}
.hero-card { padding: 1.35rem; border-top: 5px solid var(--brand); }
.theme-card { margin: 1.1rem 0; padding: 1.15rem; background: var(--ink); color: #fff; }
.theme-card .eyebrow { color: #a9decf; }
.theme-text { margin: .25rem 0; font-size: 1.08rem; font-weight: 750; }
.settings-card, .tool-card { margin: 1rem 0; padding: 1.1rem; }
.success-panel { margin-top: 1rem; padding: 1rem; background: var(--soft); }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin: 1rem 0; }
.stats-grid article { min-height: 105px; display: flex; flex-direction: column; justify-content: center; padding: 1rem; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.stats-grid strong { font-size: 1.7rem; color: var(--brand); }
.stats-grid span { color: var(--muted); font-size: .82rem; }

.button, .file-button {
  min-height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .7rem 1rem; border: 1px solid transparent; border-radius: 12px;
  font-weight: 800; text-align: center; text-decoration: none; cursor: pointer;
}
.button.primary { color: #fff; background: var(--brand); }
.button.primary:hover { background: var(--brand-dark); }
.button.secondary, .file-button { color: var(--brand-dark); background: var(--soft); border-color: #b8d7cd; }
.button.ghost { color: var(--ink); background: transparent; border-color: var(--line); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.wide { width: 100%; }
.actions { display: flex; justify-content: space-between; gap: .75rem; margin-top: 1.25rem; }
.actions > * { flex: 1; }

.choice-list { display: grid; gap: .7rem; margin: 1rem 0; }
.choice-card {
  min-height: 52px; display: flex; align-items: flex-start; gap: .75rem; width: 100%;
  padding: .9rem; border: 1.5px solid var(--line); border-radius: 14px; background: var(--surface); text-align: left; cursor: pointer;
}
.choice-card:hover { border-color: #95bcb1; }
.choice-card.selected { border-color: var(--brand); background: var(--soft); box-shadow: 0 0 0 2px rgba(23,107,91,.1); }
.choice-card input { margin-top: .28rem; accent-color: var(--brand); }
.choice-card strong { display: block; }
.choice-card small { display: block; color: var(--muted); margin-top: .18rem; }
.narrow-box { margin: 1rem 0; padding: 1rem; border-left: 4px solid var(--accent); background: var(--warning); border-radius: 10px; }

.form-stack { display: grid; gap: .55rem; margin: 1rem 0; }
label { font-weight: 750; }
label span, label small { color: var(--muted); font-size: .78rem; font-weight: 500; }
textarea, input[type="text"], input[type="number"], input[type="date"], select {
  width: 100%; min-height: 46px; padding: .72rem .78rem; border: 1.5px solid #cbd4ce; border-radius: 10px; background: #fff; resize: vertical;
}
textarea:focus-visible, input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid rgba(230,168,60,.75); outline-offset: 2px; }
.number-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.number-grid label { font-size: .84rem; }
.field-error { min-height: 1.5em; color: var(--danger); font-weight: 750; }
.field-status { min-height: 1.5em; }
.subcopy, .storage-note { color: var(--muted); }
.storage-note { padding: .85rem; border: 1px dashed #a9b8b1; border-radius: 12px; font-size: .85rem; }
.notice { margin: .9rem 0; padding: .82rem .9rem; border-radius: 12px; color: #24453d; background: var(--soft); }
.notice:empty { display: none; }
.notice.warning { background: var(--warning); color: #5c451d; }
.quote-reference { padding: .8rem 1rem; border-left: 4px solid var(--accent); background: #fff9e8; }

.translation-list { display: grid; gap: .6rem; }
.translation-row { padding: .85rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.translation-row dt { color: var(--muted); font-size: .76rem; font-weight: 800; }
.translation-row dd { margin: .2rem 0 0; font-weight: 700; }
.translation-row textarea { margin-top: .35rem; }

.card-list { display: grid; gap: .9rem; margin: 1rem 0; }
.candidate-card, .note-card { padding: 1rem; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.card-head h3 { margin: 0; font-size: 1.05rem; }
.badge-row, .tag-row { display: flex; flex-wrap: wrap; gap: .35rem; margin: .65rem 0; }
.badge, .tag { display: inline-flex; padding: .22rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 800; }
.badge { color: #fff; background: var(--brand); }
.badge.near { color: #5c451d; background: var(--warning); }
.badge.draft { color: #6d3b3d; background: #f7dfe0; }
.tag { color: #344641; background: #edf0ed; }
.operator-note { color: var(--muted); font-size: .88rem; }
.win-note { padding: .55rem .7rem; border-radius: 9px; color: #2f4d45; background: var(--soft); font-size: .8rem; }
.external-link { min-height: 44px; display: inline-flex; align-items: center; font-weight: 800; }

.judge-questions { display: grid; gap: .65rem; margin: 1rem 0; }
.judge-row { padding: .85rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.yes-no { display: flex; gap: .55rem; margin-top: .6rem; }
.yes-no button { flex: 1; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }
.yes-no button.selected { color: #fff; border-color: var(--brand); background: var(--brand); }
.progress-copy { color: var(--muted); font-weight: 700; }
.comparison-list { display: grid; gap: .65rem; margin: 1rem 0; }

.output-box { min-height: 270px; padding: 1rem; border: 1px solid #3d5350; border-radius: 16px; color: #f7f6ed; background: #172321; white-space: pre-wrap; font-family: inherit; line-height: 1.8; box-shadow: var(--shadow); }

.tool-tabs { display: flex; gap: .45rem; overflow-x: auto; padding: .25rem 0 .75rem; scrollbar-width: thin; }
.tool-tabs button { min-height: 44px; flex: 0 0 auto; padding: .55rem .8rem; border: 1px solid var(--line); border-radius: 999px; background: #fff; cursor: pointer; }
.tool-tabs button.active { color: #fff; border-color: var(--brand); background: var(--brand); }
.tool-tabs button.locked { color: #8b928f; background: #eeefed; }
.tool-card fieldset { margin: 1rem 0; border: 1px solid var(--line); border-radius: 12px; }
.sample-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .55rem; }
.result-metric { display: grid; grid-template-columns: repeat(3, 1fr); gap: .45rem; margin: 1rem 0; }
.result-metric div { padding: .65rem; border-radius: 10px; text-align: center; background: var(--soft); }
.result-metric strong { display: block; color: var(--brand); font-size: 1.1rem; }
.check-row, .toggle-row { min-height: 50px; display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.check-row input, .toggle-row input { width: 24px; height: 24px; flex: 0 0 auto; accent-color: var(--brand); }
.toggle-row small { display: block; }
.why-nav { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-top: .8rem; }
.note-row { display: flex; justify-content: space-between; gap: .75rem; color: var(--muted); font-size: .85rem; }
.note-detail-grid { display: grid; gap: .65rem; }
.note-field { padding: .75rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.note-field dt { color: var(--muted); font-size: .76rem; font-weight: 800; }
.note-field dd { margin: .25rem 0 0; white-space: pre-wrap; }

.file-button { width: 100%; margin-top: .65rem; position: relative; overflow: hidden; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.bottom-nav {
  position: fixed; left: 50%; bottom: 0; z-index: 20; transform: translateX(-50%);
  display: grid; grid-template-columns: repeat(4, 1fr); width: min(100%, 640px); padding: .45rem .45rem max(.45rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: rgba(255,253,248,.97); backdrop-filter: blur(12px); box-shadow: 0 -10px 26px rgba(23,35,33,.07);
}
.bottom-nav button { min-height: 50px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem; border: 0; border-radius: 10px; color: var(--muted); background: transparent; font-size: .72rem; cursor: pointer; }
.bottom-nav button span { font-size: 1.05rem; line-height: 1; }
.bottom-nav button.active { color: var(--brand-dark); background: var(--soft); font-weight: 850; }

.modal-backdrop { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 1rem; background: rgba(11,22,20,.62); }
.modal { width: min(100%, 500px); max-height: 86vh; overflow-y: auto; padding: 1.25rem; border-radius: 20px; background: #fff; box-shadow: 0 24px 70px rgba(0,0,0,.25); }
.modal-actions { display: grid; gap: .6rem; }
.toast { position: fixed; left: 50%; bottom: 5.25rem; z-index: 60; transform: translateX(-50%); width: min(calc(100% - 2rem), 420px); padding: .75rem 1rem; border-radius: 12px; color: #fff; background: var(--ink); box-shadow: var(--shadow); text-align: center; }

@media (max-width: 390px) {
  main { padding-inline: .85rem; }
  .app-header { padding-inline: .85rem; }
  .number-grid, .result-metric { grid-template-columns: 1fr; }
  .actions { flex-direction: column-reverse; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; }
}
