/* Shared design tokens + base component styles for all pages. */

:root {
  color-scheme: light dark;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-alt: #f1f1f3;
  --border: #e3e3e7;
  --text: #17171a;
  --text-muted: #6b6b75;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #b45309;
  --shadow-sm: 0 1px 2px rgba(20, 20, 25, 0.05), 0 1px 1px rgba(20, 20, 25, 0.04);
  --shadow-md: 0 8px 24px rgba(20, 20, 25, 0.08);

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 999px;

  --topbar-h: 52px;
  --tabbar-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e10;
    --surface: #1a1a1d;
    --surface-alt: #232327;
    --border: #2c2c31;
    --text: #f2f2f3;
    --text-muted: #97979f;
    --accent: #4d8dff;
    --accent-contrast: #0a0a0b;
    --danger: #f87171;
    --success: #4ade80;
    --warning: #fbbf24;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Malgun Gothic", Arial, sans-serif;
  margin: 0;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--topbar-h) + var(--sp-4)) var(--sp-4)
    calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--sp-5));
}

h1 { font-size: 1.35rem; margin: 0 0 var(--sp-1); letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: var(--sp-6) 0 var(--sp-2); letter-spacing: -0.01em; }

p.subtitle, .muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

a { color: var(--accent); }

/* --- form controls --- */
input, select, textarea, button {
  font: inherit;
  font-size: 1rem;
  color: var(--text);
}

input, select, textarea {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

textarea { resize: vertical; }

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-full);
  padding: 11px 20px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-contrast);
  min-height: 44px;
  transition: transform 0.1s ease, opacity 0.15s ease, background 0.15s ease;
}

button:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

button.secondary { background: var(--surface-alt); color: var(--text); }
button.danger { background: var(--danger); color: white; }
button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

/* --- layout helpers --- */
.bar {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  flex-wrap: wrap;
  margin: var(--sp-4) 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-5);
}

.empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.9rem;
}

/* --- mode switch: segmented control, either JS-toggled buttons (reference.html) or
   real page links (toeic_*.html sub-nav via toeic-nav.js) --- */
.mode-switch { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.mode-switch button, .mode-switch a {
  flex: 1;
  min-width: 90px;
  padding: 10px;
  text-align: center;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}
.mode-switch button:not(.active), .mode-switch a:not(.active) { background: var(--surface-alt); color: var(--text); }

/* --- MCQ vocab quiz (vocab.html, toeic.html) --- */
.mcq-choices { display: flex; flex-direction: column; gap: var(--sp-2); margin: var(--sp-3) 0; }
.mcq-choice {
  width: 100%;
  background: var(--surface-alt);
  color: var(--text);
  text-align: left;
  padding: 12px 16px;
}
.mcq-choice.correct { background: color-mix(in srgb, var(--success) 25%, transparent); color: var(--text); }
.mcq-choice.wrong { background: color-mix(in srgb, var(--danger) 25%, transparent); color: var(--text); }
.mcq-choice:disabled { opacity: 1; }

/* --- tool-card grid: index.html's app launcher, reused by toeic.html's part hub --- */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
}
@media (max-width: 420px) {
  .grid { grid-template-columns: 1fr; }
}
a.tool-card {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}
a.tool-card:active { transform: scale(0.98); }
.tool-emoji { font-size: 1.8rem; display: block; margin-bottom: var(--sp-2); }
.tool-title { font-weight: 600; font-size: 1rem; }
.tool-desc { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; }
.done-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  background: color-mix(in srgb, var(--success) 20%, transparent);
  color: var(--success);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  margin-left: 4px;
}

.daily-log { list-style: none; padding: 0; margin: 0; }
.daily-log li {
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.daily-log li:last-child { border-bottom: none; }
.daily-log .log-date { font-weight: 600; margin-right: var(--sp-2); }

/* --- top bar --- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding-left: var(--sp-4);
  padding-right: var(--sp-4);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.topbar .app-title {
  font-weight: 700;
  font-size: 0.95rem;
  flex: 1;
}

.topbar .nav-date {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.topbar .user-badge {
  font-size: 0.8rem;
  padding: 6px 12px;
  min-height: auto;
  border-radius: var(--radius-full);
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
}

/* --- bottom tab bar --- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  z-index: 100;
}

.tabbar a {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: var(--tabbar-h);
  padding: 0 2px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.62rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tabbar a .tab-emoji { font-size: 1.15rem; line-height: 1; }
.tabbar a.active { color: var(--accent); }
