/* デザイントークン ------------------------------------------------------
   学習に集中させる静かな配色。AI既定のクリーム×テラコッタは避け、
   紙面のクール白 × インディゴのインクで「集中/整理」の質感にする。
   コントラストは全て 4.5:1 以上を満たす値に固定。 */
:root {
  --bg: #f4f6f8;        /* 背景（クール白） */
  --surface: #ffffff;   /* カード面 */
  --ink: #1a1d23;       /* 本文（対 surface 15:1超） */
  --muted: #5a6270;     /* 補足（対 surface 5.4:1） */
  --accent: #364fc7;    /* インディゴ（対 白文字 6.4:1） */
  --accent-ink: #ffffff;
  --border: #e1e4e8;
  --danger: #b42318;    /* エラー（対 surface 6.1:1） */

  --radius: 10px;
  --font: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic",
    "Noto Sans JP", sans-serif;

  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body,
#root {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: 16px; /* 本文最小16px（アクセシビリティ要件） */
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
}

/* キーボード操作の可視フォーカス */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* レイアウト -------------------------------------------------------------- */
.center {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  text-align: center;
}

/* 署名: わずかにずらして重ねたカード */
.mark {
  display: inline-block;
  width: 44px;
  height: 44px;
  margin-bottom: 16px;
  position: relative;
}
.mark i {
  position: absolute;
  inset: 0;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
}
.mark i:nth-child(1) {
  transform: translate(-6px, -6px) rotate(-8deg);
  opacity: 0.35;
}
.mark i:nth-child(2) {
  transform: translate(3px, 3px) rotate(5deg);
  opacity: 0.6;
}

.auth-card h1 {
  font-size: 26px;
  letter-spacing: 0.04em;
  margin: 0 0 4px;
}
.sub {
  color: var(--muted);
  margin: 0 0 24px;
}

/* ボタン ----------------------------------------------------------------- */
.btn-primary {
  width: 100%;
  font: inherit;
  font-weight: 600;
  padding: 12px 16px;
  color: var(--accent-ink);
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}
.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-ghost {
  font: inherit;
  padding: 6px 12px;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.error:empty {
  display: none;
}
.error {
  color: var(--danger);
  margin: 16px 0 0;
  font-size: 15px;
}

/* アプリシェル ----------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 700;
  letter-spacing: 0.04em;
}
.spacer {
  flex: 1;
}
.who {
  color: var(--muted);
  font-size: 14px;
}
.content {
  padding: 40px 20px;
  max-width: 720px;
  margin: 0 auto;
}
.placeholder {
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* Slice 1: ナビ・フォーム・学習 -------------------------------------- */
.nav {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}
.tab {
  font: inherit;
  padding: 6px 12px;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.tab.active {
  color: var(--accent);
  background: #eef1fb;
  font-weight: 600;
}

.content h2 {
  font-size: 20px;
  margin: 0 0 16px;
}

.fld {
  display: block;
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
}
.fld input,
.fld textarea,
.fld select {
  display: block;
  width: 100%;
  margin-top: 6px;
  font: inherit;
  font-size: 16px; /* iOSの入力時ズーム防止も兼ねる */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.fld textarea {
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.btn-inline {
  width: auto;
}

.result {
  margin-top: 16px;
  color: var(--ink);
  font-size: 15px;
}
.muted-line {
  color: var(--muted);
}

/* 学習 */
.study {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.progress {
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.08em;
}
.card {
  width: 100%;
  max-width: 480px;
  min-height: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
}
.face.front {
  font-size: 28px;
  font-weight: 600;
}
.face.back {
  border-top: 1px solid var(--border);
  padding-top: 20px;
  width: 100%;
}
.b-main {
  font-size: 20px;
}
.b-sub {
  color: var(--muted);
  font-size: 15px;
  margin-top: 8px;
}
.b-pos {
  display: inline-block;
  margin-top: 12px;
  padding: 2px 10px;
  font-size: 13px;
  color: var(--accent);
  background: #eef1fb;
  border-radius: 999px;
}
.reveal {
  font: inherit;
  padding: 10px 20px;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 999px;
  cursor: pointer;
}

.grade {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 480px;
}
.btn-right,
.btn-wrong {
  flex: 1;
  font: inherit;
  font-weight: 600;
  padding: 14px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  color: #fff;
}
.btn-right {
  background: #1e7d4f; /* 対 白文字 4.7:1 */
}
.btn-wrong {
  background: var(--danger);
}
.quit {
  margin-top: 4px;
}
.summary {
  font-size: 20px;
}

/* Slice 2: 進捗 ------------------------------------------------------- */
.sub-h {
  font-size: 15px;
  color: var(--muted);
  margin: 28px 0 8px;
}
.small {
  font-size: 13px;
}
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}
.kpi-num {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}
.kpi-lbl {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}
table.stat {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.stat th,
table.stat td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
table.stat thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
}
table.stat td {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.stat tbody th {
  font-weight: 500;
}

/* Slice 3: 取り込み/プレビュー/管理 ---------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.panel .sub-h {
  margin-top: 0;
}
.fld.inline {
  display: inline-block;
  margin-right: 12px;
}
.fld.inline input,
.fld.inline select {
  width: auto;
  display: inline-block;
  margin-top: 0;
  margin-left: 6px;
}
.prompt-box {
  width: 100%;
  margin: 8px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

/* プレビュー表 */
.preview-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
table.preview {
  border-collapse: collapse;
  font-size: 13px;
  min-width: 720px;
}
table.preview th,
table.preview td {
  border-bottom: 1px solid var(--border);
  padding: 4px 6px;
  text-align: left;
}
table.preview thead th {
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--surface);
}
table.preview input[type="text"],
table.preview input:not([type]) {
  width: 110px;
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
}
table.preview input.wide {
  width: 160px;
}
table.preview input.narrow {
  width: 48px;
}

/* 管理 */
.mtools {
  gap: 8px;
  margin-bottom: 8px;
}
.mtools #mq {
  flex: 1;
  min-width: 160px;
  font: inherit;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.mtools select {
  font: inherit;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
}
.mlist {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mrow {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  flex-wrap: wrap;
}
.mrow-main {
  flex: 1;
  min-width: 160px;
}
.mterm {
  font-weight: 600;
}
.mmean {
  color: var(--muted);
  font-size: 14px;
}
.mtags {
  margin-top: 4px;
}
.chip {
  display: inline-block;
  font-size: 12px;
  color: var(--accent);
  background: #eef1fb;
  border-radius: 999px;
  padding: 1px 8px;
  margin-right: 4px;
}
.mrow-stat {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.mrow-act {
  display: flex;
  gap: 6px;
}
.btn-ghost.danger {
  color: var(--danger);
  border-color: #f2c4c0;
}
.editor {
  max-width: 480px;
}

/* Slice 4: 警告バナー・注記 ------------------------------------------- */
.banner {
  background: #fff4e5;
  border: 1px solid #f0c98a;
  color: #7a4a00; /* 対 背景 4.8:1 */
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 14px;
}
.note {
  margin: 16px 0 0;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--muted);
  background: #eef1fb;
  border-radius: 8px;
}
