/* iPhone / iPad 向けのスタイル。色は :root の変数でまとめて管理する */
:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --text: #1b1f24;
  --text-sub: #5d6670;
  --border: #d3d9e0;
  --primary: #1f4e79;
  --primary-text: #ffffff;
  --selected-bg: #1f4e79;
  --selected-text: #ffffff;
  --ok: #1565c0;
  --ng: #c62828;
  --danger: #c62828;
  --notice-bg: #fff6d6;
  --mark-correct: #e53935; /* ◯は赤 */
  --mark-wrong: #1e5fd6;   /* ✕は青 */
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1c2127;
    --text: #e7ebef;
    --text-sub: #a2acb6;
    --border: #39414a;
    --primary: #2b6aa3;
    --selected-bg: #5b9bd5;
    --selected-text: #0b1520;
    --ok: #6ab0f3;
    --ng: #ef6c6c;
    --danger: #ef6c6c;
    --notice-bg: #3a3420;
    --mark-correct: #ff5a52;
    --mark-wrong: #5b9bff;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  touch-action: manipulation; /* ダブルタップでの拡大を防ぐ */
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.loading, .empty { text-align: center; padding: 48px 16px; color: var(--text-sub); }
.error { color: var(--danger); padding: 0 16px; }
.note { color: var(--text-sub); font-size: 13px; margin: 8px 0 0; }
.notice { background: var(--notice-bg); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 12px; }

.screen { min-height: 100vh; min-height: 100dvh; padding-bottom: calc(96px + var(--safe-bottom)); }
.screen.center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; }
.content { max-width: 720px; margin: 0 auto; padding: 16px calc(16px + var(--safe-right)) 16px calc(16px + var(--safe-left)); }

/* ヘッダー */
.header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 8px) calc(8px + var(--safe-right)) 8px calc(8px + var(--safe-left));
  background: var(--primary); color: var(--primary-text);
}
.header h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-side { flex: 0 0 auto; min-width: 88px; display: flex; }
.header-right { justify-content: flex-end; }
.header-button { background: none; border: none; color: inherit; padding: 8px 6px; font-size: 15px; min-height: 44px; }

/* 設定画面 */
.card-section { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.card-section h2 { margin: 0 0 10px; font-size: 15px; color: var(--text-sub); font-weight: 600; }
.field + .field, .segmented + .field { margin-top: 14px; }
.field-label { display: block; font-size: 15px; margin-bottom: 6px; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented button {
  flex: 1 1 auto; min-width: 64px; min-height: 44px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
}
.segmented button.selected { background: var(--selected-bg); color: var(--selected-text); border-color: var(--selected-bg); font-weight: 700; }
select { width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-switch { flex: 0 0 auto; width: 52px; height: 32px; border-radius: 16px; background: var(--border); position: relative; transition: background 0.15s; }
.toggle-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.3); transition: transform 0.15s; }
.toggle input:checked + .toggle-switch { background: #34c759; }
.toggle input:checked + .toggle-switch::after { transform: translateX(20px); }
.toggle input:focus-visible + .toggle-switch { outline: 2px solid var(--primary); outline-offset: 2px; }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.primary-button {
  width: 100%; max-width: 420px; min-height: 56px;
  border: none; border-radius: 28px; background: var(--primary); color: var(--primary-text);
  font-size: 19px; font-weight: 700;
}
.primary-button:disabled { opacity: 0.5; }
.secondary-button, .danger-button { min-height: 48px; padding: 0 20px; border-radius: 24px; font-weight: 600; }
.secondary-button { border: 1px solid var(--border); background: var(--surface); }
.danger-button { border: none; background: var(--danger); color: #fff; }
.danger-link { display: block; margin: 24px auto 0; background: none; border: none; color: var(--danger); min-height: 44px; }

/* 課題画面：画面全体を使い、スクロール・拡大・長押しメニューを止める */
.task-screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding: calc(var(--safe-top) + 4px) calc(12px + var(--safe-right)) calc(var(--safe-bottom) + 12px) calc(12px + var(--safe-left));
  background: var(--bg);
  touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.task-top { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.text-button, .text-button-spacer { min-width: 72px; }
.text-button { background: none; border: none; color: var(--primary); font-size: 17px; min-height: 44px; text-align: left; padding: 0 4px; }
.text-button.danger { color: var(--danger); }
@media (prefers-color-scheme: dark) { .text-button { color: var(--selected-bg); } }
.task-progress { color: var(--text-sub); font-weight: 600; font-variant-numeric: tabular-nums; }
.task-grid { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px 0; }
.cards { display: grid; }
.word-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10%;
  overflow: hidden; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.word-card .emoji { line-height: 1; pointer-events: none; }
.word-card img { width: 80%; height: 80%; object-fit: contain; pointer-events: none; }
.word-card .word-label { font-weight: 600; pointer-events: none; }
.mark { position: absolute; inset: 15%; width: 70%; height: 70%; pointer-events: none; fill: none; stroke-width: 10; stroke-linecap: round; }
.mark-correct { stroke: var(--mark-correct); }
.mark-wrong { stroke: var(--mark-wrong); }
.task-bottom { display: flex; justify-content: center; min-height: 56px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 20; }
.modal { background: var(--surface); border-radius: 16px; padding: 20px; max-width: 360px; width: 100%; }
.modal p { margin: 0 0 8px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

/* 結果 */
.rows { margin: 0; }
.rows > div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.rows > div:last-child { border-bottom: none; }
.rows dt { color: var(--text-sub); }
.rows dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.trials { width: 100%; border-collapse: collapse; font-size: 15px; }
.trials th { text-align: left; font-weight: 600; color: var(--text-sub); font-size: 13px; padding: 6px 4px; border-bottom: 1px solid var(--border); }
.trials td { padding: 8px 4px; border-bottom: 1px solid var(--border); }
.trials .num { text-align: right; font-variant-numeric: tabular-nums; }
.trials .ok { color: var(--ok); }
.trials .ng { color: var(--ng); }

.session-list { list-style: none; margin: 12px 0 0; padding: 0; }
.session-list li + li { margin-top: 8px; }
.session-list button {
  width: 100%; text-align: left; padding: 12px 14px; min-height: 60px;
  background: var(--surface); border: none; border-radius: var(--radius);
  display: flex; flex-direction: column;
}
.session-date { font-weight: 700; }
.session-sub { color: var(--text-sub); font-size: 14px; }

/* 新しいバージョンの案内 */
.update-bar {
  position: fixed; left: 12px; right: 12px; bottom: calc(96px + var(--safe-bottom)); z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 480px; margin: 0 auto; padding: 10px 12px 10px 16px;
  background: var(--text); color: var(--bg); border-radius: 14px; box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.update-bar button { border: none; border-radius: 10px; min-height: 40px; padding: 0 16px; background: var(--primary); color: var(--primary-text); font-weight: 700; }
