:root {
  --bg: #0a0f1c;
  --surface: #0f172a;
  --elev: #1a1f3a;
  --elev-2: #1e2548;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --muted: #8896ab;
  --line: #2a3441;
  --line-subtle: #1e2936;
  --brand: #06b6d4;
  --brand-hover: #0891b2;
  --brand-2: #8b5cf6;
  --brand-gradient: linear-gradient(135deg, #06b6d4 0%, #8b5cf6 100%);
  --accent: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --ring: rgba(6, 182, 212, 0.2);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.25);
  --shadow-brand: 0 8px 32px rgba(6, 182, 212, 0.2);
  /* Optical nudge for select icons (tweak 0px~2px as needed) */
  --select-icon-nudge-y: 1px;
}

[data-theme="light"] {
  --bg: #fafbfc;
  --surface: #ffffff;
  --elev: #ffffff;
  --elev-2: #f8fafc;
  --text: #0f172a;
  --text-secondary: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-subtle: #f3f4f6;
  --brand: #0891b2;
  --brand-hover: #0e7490;
  --brand-2: #7c3aed;
  --brand-gradient: linear-gradient(135deg, #0891b2 0%, #7c3aed 100%);
  --accent: #d97706;
  --success: #059669;
  --danger: #dc2626;
  --warning: #d97706;
  --ring: rgba(8, 145, 178, 0.15);
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
  --shadow-brand: 0 4px 24px rgba(8, 145, 178, 0.15);
}
/* Base styles with enhanced typography */
* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(ellipse 1400px 700px at 20% 10%, rgba(6, 182, 212, 0.08), transparent),
    radial-gradient(ellipse 900px 500px at 80% 90%, rgba(139, 92, 246, 0.08), transparent),
    radial-gradient(ellipse 600px 400px at 50% 50%, rgba(245, 158, 11, 0.04), transparent),
    var(--bg);
  color: var(--text);
  font: 400 16px/1.7 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "YuGothic", Meiryo, "Noto Sans JP",
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.011em;
}

/* Accessible selection colors */
::selection {
  background: color-mix(in oklch, var(--brand) 35%, transparent);
  color: var(--text);
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Enhanced Header Design */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20000;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  background: color-mix(in oklch, var(--surface) 85%, transparent);
  border-bottom: 1px solid var(--line-subtle);
  box-shadow: var(--shadow-sm);
  margin-bottom: 32px;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 0;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--brand-gradient);
  box-shadow: var(--shadow-brand), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: hidden;
}

.brand-logo::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    transparent 0%,
    rgba(255, 255, 255, 0.1) 50%,
    transparent 100%
  );
  animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {
  0%,
  100% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
}

.brand {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.925rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

/* Enhanced Theme Toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--elev);
  border: 1px solid var(--line);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.theme-toggle::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--brand-gradient);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.theme-toggle:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow), 0 0 0 3px var(--ring);
  transform: translateY(-1px);
}

.theme-toggle:hover::before {
  opacity: 0.1;
}

.theme-toggle:active {
  transform: translateY(0);
  transition: transform 0.1s ease;
}

.theme-toggle .icon-moon {
  display: none;
  position: relative;
  z-index: 1;
  font-size: 1.1rem;
}

.theme-toggle .icon-sun {
  position: relative;
  z-index: 1;
  font-size: 1.1rem;
}

/* Ensure inline SVG icons in the theme toggle have consistent sizing */
.theme-toggle svg {
  width: 20px;
  height: 20px;
  display: block;
  stroke: currentColor;
  fill: none;
}

[data-theme="light"] .theme-toggle .icon-sun {
  display: inline;
}
[data-theme="light"] .theme-toggle .icon-moon {
  display: none;
}
[data-theme="dark"] .theme-toggle .icon-sun {
  display: none;
}
[data-theme="dark"] .theme-toggle .icon-moon {
  display: inline;
}

/* Enhanced Footer */
.site-footer {
  border-top: 1px solid var(--line-subtle);
  padding: 24px 0;
  color: var(--muted);
  margin-top: 48px;
  background: color-mix(in oklch, var(--surface) 50%, transparent);
}

.noscript-banner {
  margin: 8px auto 0;
  max-width: 960px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid color-mix(in oklch, var(--warning) 40%, var(--line));
  background: color-mix(in oklch, var(--warning) 18%, var(--surface));
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.footer-link {
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.footer-link:hover {
  color: var(--brand);
  background: color-mix(in oklch, var(--brand) 10%, transparent);
}

/* Enhanced Card Design */
.card {
  background: var(--elev);
  padding: 32px;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  position: relative;
  /* ドロップダウンがカードの外へ展開されるため visible に変更 */
  overflow: visible;
  animation: slide-up 0.6s cubic-bezier(0.4, 0, 0.2, 1) both;
}

/* 統一感のある縦余白: カードが連続する場合に一定の隙間を付与 */
.card + .card {
  margin-top: 24px;
}

.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--brand-gradient);
  opacity: 0.6;
}

.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slide-up {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.hero {
  margin-bottom: 24px;
  text-align: center;
  background: var(--elev-2);
  border: 1px solid var(--line-subtle);
}

.hero-title {
  margin: 0 0 12px;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.3;
  color: var(--text);
}

.hero-text {
  margin: 0;
  color: var(--text-secondary);
  font-size: 1.1rem;
  font-weight: 500;
  line-height: 1.6;
}

/* Subtitle style actually used in template */
.hero-sub {
  margin: 6px 0 0;
  color: var(--text-secondary);
  font-size: 1rem;
}

/* Enhanced Form Design */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  animation-delay: 0.2s;
}

@media (max-width: 840px) {
  .form-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

label {
  font-weight: 600;
  font-size: 0.925rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.input-wrap {
  position: relative;
}

/* Iconified inputs */
.input-wrap.has-icon input,
.input-wrap.has-icon select {
  padding-left: 42px;
  position: relative; /* keep below icon/suffix */
  z-index: 1;
}
.input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  font-size: 1.05rem;
  z-index: 2; /* above input */
}
.input-icon svg,
.btn-icon svg {
  width: 18px;
  height: 18px;
  display: block;
  stroke: currentColor;
  fill: none;
}

input[type="number"] {
  width: 100%;
  padding: 14px 48px 14px 16px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  outline: none;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
}

input[type="number"]:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--ring), var(--shadow);
  transform: translateY(-1px);
}

/* Text/Password Inputs */
input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  outline: none;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
}

/* Select (Dropdown) - Modern style aligned with inputs */
select {
  width: 100%;
  padding: 14px 48px 14px 16px; /* room for arrow */
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  outline: none;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  cursor: pointer;
}

select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--ring), var(--shadow);
  transform: translateY(-1px);
}

select:hover:not(:focus) {
  border-color: color-mix(in oklch, var(--brand) 60%, var(--line));
}

/* Custom arrow using the wrapper that already exists */
.input-wrap:has(select:not(.sr-only-select))::after {
  content: "";
  position: absolute;
  right: 14px;
  top: calc(50% + var(--select-icon-nudge-y));
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  width: 18px;
  height: 18px;
  display: inline-block;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 18px 18px;
  /* chevron-down using currentColor */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}
/* When custom select is active, hide the original leading .input-icon to avoid double icons */
.input-wrap:has(.select-custom:not([hidden])) .input-icon {
  display: none;
}

/* Hide native select visually when enhanced, keep for a11y/events */
.sr-only-select {
  position: absolute !important;
  inset: 0 auto auto 0 !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: 0 !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Custom select (modern dropdown) */
.select-custom {
  position: relative;
  z-index: 10000; /* 前面に */
}
.select-trigger {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 18px 1fr 18px; /* icon | label | caret */
  align-items: center;
  column-gap: 10px;
  padding: 14px 16px; /* uniform padding; grid handles icon/caret space */
  line-height: 1; /* stable vertical center basis */
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  outline: none;
  font-size: 1rem;
  font-weight: 600;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  box-sizing: border-box;
}
.select-trigger:hover {
  border-color: var(--brand);
}
.select-trigger:focus-visible {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--ring), var(--shadow);
}
.select-leading {
  position: static;
  transform: translateY(var(--select-icon-nudge-y));
  color: var(--muted);
  font-size: 1.05rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.select-label {
  margin-left: 0; /* grid gap handles spacing */
}
.select-caret {
  position: static;
  transform: translateY(var(--select-icon-nudge-y));
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0; /* avoid baseline offset */
  width: 18px;
  height: 18px;
}
.select-caret svg {
  stroke: currentColor;
  display: block; /* align exact center in flex */
}
/* Ensure consistent sizing/alignment for select icons */
.select-leading svg,
.select-caret svg {
  width: 18px;
  height: 18px;
  display: block; /* remove baseline gap */
}
.select-list {
  position: absolute;
  z-index: 10001;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  border-radius: 12px;
  padding: 8px;
  font-size: 0.95rem;
}
.select-custom .select-list {
  display: none;
}
.select-custom.open .select-list {
  display: block;
}

/* ドロップダウン開時に親カードも最前面にする */
.card.raise {
  z-index: 10000;
}
.select-option {
  list-style: none;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
}
.select-option:hover {
  background: color-mix(in oklch, var(--brand) 10%, var(--surface));
}
.select-option[aria-selected="true"] {
  background: color-mix(in oklch, var(--brand) 18%, var(--surface));
  border: 1px solid color-mix(in oklch, var(--brand) 40%, var(--line));
}

/* グループ見出し（科目） */
.select-group {
  list-style: none;
  padding: 8px 10px 6px;
  margin: 6px 6px 4px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0.02em;
  border-top: 1px solid var(--line-subtle);
}

/* 科目別カラー（テーマ対応の控えめな帯） */
.select-group[data-subject] {
  border-radius: 8px;
  padding: 8px 10px 6px;
}
.select-group[data-subject^="英"] {
  /* 外国語 */
  background: color-mix(in oklch, var(--brand) 12%, transparent);
  color: color-mix(in oklch, var(--brand) 85%, var(--text));
}
.select-group[data-subject^="国"] {
  /* 国語 */
  background: color-mix(in oklch, var(--accent) 12%, transparent);
  color: color-mix(in oklch, var(--accent) 85%, var(--text));
}
.select-group[data-subject^="数"] {
  /* 数学 */
  background: color-mix(in oklch, var(--success) 12%, transparent);
  color: color-mix(in oklch, var(--success) 80%, var(--text));
}
.select-group[data-subject^="理"],
.select-group[data-subject^="化"],
.select-group[data-subject^="物"],
.select-group[data-subject^="生"] {
  /* 理系科目 */
  background: color-mix(in oklch, #22c55e 12%, transparent);
  color: color-mix(in oklch, #22c55e 80%, var(--text));
}
.select-group[data-subject^="社"],
.select-group[data-subject*="地"],
.select-group[data-subject*="歴"],
.select-group[data-subject*="公"] {
  /* 社会系科目 */
  background: color-mix(in oklch, #f43f5e 12%, transparent);
  color: color-mix(in oklch, #f43f5e 80%, var(--text));
}
.select-group[data-subject="その他"] {
  background: color-mix(in oklch, var(--muted) 10%, transparent);
  color: var(--muted);
}

input[type="text"]:focus,
input[type="password"]:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--ring), var(--shadow);
  transform: translateY(-1px);
}

/* Alerts */
.alert {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: color-mix(in oklch, var(--danger) 15%, var(--surface));
  color: var(--text);
}

.alert.error {
  background: color-mix(in oklch, var(--danger) 22%, var(--surface));
  border-color: color-mix(in oklch, var(--danger) 40%, var(--line));
}

/* Generic Button (for <a> and others) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  text-decoration: none;
  background: var(--elev);
  color: var(--text);
  border: 1px solid var(--line);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
}

.btn:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow), 0 0 0 3px var(--ring);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--line);
}

.btn-ghost {
  background: transparent;
  border: 1px solid transparent;
}

.btn-sm {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.95rem;
}

/* Login Card */
.login-card {
  max-width: 420px;
  margin: 0 auto;
}
.login-title {
  margin: 0 0 8px;
  font-size: 1.4rem;
  font-weight: 700;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.login-subtitle {
  margin: 0 0 16px;
  color: var(--muted);
  font-weight: 500;
}

/* Brand ghost button (for header login/logout) */
.btn-ghost-brand {
  color: var(--brand);
  border-color: color-mix(in oklch, var(--brand) 50%, var(--line));
}
.btn-ghost-brand:hover {
  color: white;
  background: var(--brand-gradient);
  border-color: transparent;
  box-shadow: var(--shadow-brand), 0 0 0 3px var(--ring);
}
/* Active state for header nav buttons */
.btn-ghost-brand.is-active {
  color: white;
  background: var(--brand-gradient);
  border-color: transparent;
  box-shadow: var(--shadow-brand);
}
.btn-ghost-brand.is-active:hover {
  box-shadow: var(--shadow-brand), 0 0 0 3px var(--ring);
}

input[type="number"]:hover:not(:focus) {
  border-color: color-mix(in oklch, var(--brand) 60%, var(--line));
}

.suffix {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  pointer-events: none;
  z-index: 2; /* above input */
}

fieldset.field {
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

legend {
  padding: 0 12px;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.925rem;
}

.help {
  color: var(--muted);
  font-size: 0.825rem;
  font-weight: 500;
  margin-top: 2px;
}
.radios {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 8px;
}

@media (max-width: 640px) {
  .radios {
    grid-template-columns: 1fr;
  }
}

.radio {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

/* 単語帳選択セクションの左右2カラムレイアウト */
/* 左右分割を確実にするためのフレックスフォールバック */
.series-grid {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  width: 100%;
}
.series-grid > fieldset {
  flex: 0 0 280px; /* 左の科目カラムを固定幅に */
  max-width: 320px;
}
.series-grid > .field {
  flex: 1 1 auto; /* 右の単語帳は可変 */
  min-width: 0; /* はみ出し対策 */
}

/* 対応ブラウザではグリッドでより安定させる */
@supports (display: grid) {
  .series-grid {
    display: grid;
    grid-template-columns: minmax(240px, 320px) 1fr;
  }
  .series-grid > fieldset,
  .series-grid > .field {
    width: auto;
  }
}

@media (max-width: 720px) {
  .series-grid {
    display: block; /* フォールバックと整合 */
  }
}

/* 科目ラジオを縦並びに美しく配置 */
.radios-vertical {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.radios-vertical .radio {
  display: flex;
  width: 100%;
  justify-content: flex-start;
}

.radio::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--brand-gradient);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.radio:hover {
  border-color: var(--brand);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.radio:hover::before {
  opacity: 0.05;
}

.radio:has(input:checked) {
  border-color: var(--brand);
  background: color-mix(in oklch, var(--brand) 8%, var(--surface));
  box-shadow: var(--shadow-brand);
}

.radio:has(input:checked)::before {
  opacity: 0.1;
}

.radio input {
  accent-color: var(--brand);
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

/* Custom radio mark */
.radio .r-mark {
  width: 18px;
  height: 18px;
  border-radius: 9999px;
  border: 2px solid color-mix(in oklch, var(--brand) 60%, var(--line));
  position: relative;
  flex: 0 0 auto;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
  background: color-mix(in oklch, var(--surface) 90%, transparent);
}
.radio .r-mark::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 9999px;
  background: var(--brand-gradient);
  transform: scale(0);
  transition: transform 0.15s ease;
}
.radio:has(input:checked) .r-mark::after {
  transform: scale(1);
}
.radio .r-label {
  position: relative;
  z-index: 1;
}

/* 出題形式（direction）だけをセグメント風に */
.direction-radios {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 12px;
}
.direction-radios .radio {
  justify-content: center;
  gap: 12px;
  padding: 14px 18px;
  font-weight: 700;
}
.direction-radios .radio span {
  letter-spacing: 0.02em;
}
.direction-radios .radio:has(input:checked) {
  background: color-mix(in oklch, var(--brand) 14%, var(--surface));
}
.direction-radios .radio input {
  transform: scale(1.1);
}
@media (max-width: 640px) {
  .direction-radios {
    grid-template-columns: 1fr 1fr;
  }
}

.db-stats {
  display: block;
  font-size: 0.8em;
  color: var(--muted);
  margin-top: 2px;
  font-weight: 400;
}
.errors {
  background: color-mix(in oklch, var(--danger) 12%, var(--surface));
  color: var(--danger);
  padding: 16px;
  border-radius: 12px;
  margin: 12px 0;
  border: 1px solid color-mix(in oklch, var(--danger) 30%, var(--line));
  box-shadow: var(--shadow-sm);
  font-weight: 500;
}

.errors ul {
  margin: 0;
  padding-left: 16px;
}

.actions {
  margin-top: 12px;
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  padding-top: 8px;
}

/* PDF Preview */
.preview-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in oklch, black 55%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  z-index: 30000;
}

.preview-overlay.hidden {
  display: none;
}

.preview-dialog {
  width: min(1100px, 96vw);
  max-height: 92vh;
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  padding: 16px;
}

body.no-scroll {
  overflow: hidden;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.preview-tabs {
  display: inline-flex;
  gap: 8px;
}

.preview-tabs .tab {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.preview-tabs .tab.active {
  border-color: var(--brand);
  box-shadow: var(--shadow-brand);
}

.preview-title {
  margin: 0;
  font-size: 1.1rem;
}

.preview-actions {
  display: flex;
  gap: 8px;
}

.preview-actions button {
  min-width: 120px;
  padding: 12px 20px;
}

.preview-body {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
}

#pdfFrame,
#pdfFrameQuiz,
#pdfFrameAnswers {
  width: 100%;
  max-width: 100%;
  height: min(75vh, 900px);
  border: 0;
  display: block;
  background: #fff;
}

.preview-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Enhanced Button Design */
.btn-primary,
button.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--brand-gradient);
  color: white;
  border: 0;
  padding: 16px 32px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-brand);
  position: relative;
  overflow: hidden;
  min-width: 180px;
  letter-spacing: -0.01em;
}

.btn-primary::before,
button.btn-primary::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.btn-primary:hover,
button.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(6, 182, 212, 0.3), 0 4px 16px rgba(139, 92, 246, 0.2);
}

.btn-primary:hover::before,
button.btn-primary:hover::before {
  opacity: 1;
}

.btn-primary:active,
button.btn-primary:active {
  transform: translateY(-1px);
  transition: transform 0.1s ease;
}

.btn-icon {
  font-size: 1.2rem;
  position: relative;
  z-index: 1;
}
.btn-icon .spin {
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.btn-primary span:not(.btn-icon),
button span:not(.btn-icon) {
  position: relative;
  z-index: 1;
}

/* Disabled button state: clearer gray monochrome */
.btn-primary:disabled,
button.btn-primary:disabled,
.btn-primary[aria-disabled="true"] {
  background: #6b7280; /* Gray 500 */
  background-image: none;
  color: #f3f4f6; /* near-white for contrast */
  border: 0;
  box-shadow: none;
  transform: none !important;
  cursor: not-allowed;
}

.btn-primary:disabled::before,
button.btn-primary:disabled::before,
.btn-primary[aria-disabled="true"]::before {
  content: none;
}

/* Keep brand look while loading even if disabled for safety */
.btn-primary.is-loading:disabled {
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: var(--shadow-brand);
  cursor: wait;
}

/* Light Mode Enhancements */
[data-theme="light"] body {
  background: radial-gradient(ellipse 1400px 700px at 20% 10%, rgba(8, 145, 178, 0.06), transparent),
    radial-gradient(ellipse 900px 500px at 80% 90%, rgba(124, 58, 237, 0.06), transparent),
    radial-gradient(ellipse 600px 400px at 50% 50%, rgba(217, 119, 6, 0.03), transparent), var(--bg);
}

/* Responsive Design Improvements */
@media (max-width: 640px) {
  .container {
    padding: 0 16px;
  }

  .card {
    padding: 24px 20px;
  }

  .hero-title {
    font-size: 1.5rem;
  }

  .header-inner {
    padding: 16px 0;
    gap: 12px;
    flex-wrap: wrap;
  }

  .brand {
    font-size: 1.25rem;
  }

  .tagline {
    font-size: 0.875rem;
    display: none; /* モバイルでは省略してコンパクトに */
  }

  .brand-wrap {
    flex-wrap: wrap;
  }

  .header-right {
    margin-left: auto;
  }

  .theme-toggle {
    width: 38px;
    height: 38px;
  }

  /* アクションボタンはフル幅で押しやすく */
  .actions {
    flex-direction: column;
    align-items: stretch;
  }
  .actions .btn-primary,
  .actions button {
    width: 100%;
    min-width: 0;
    padding: 14px 16px;
  }

  /* プレビュー操作を上部にまとめて見やすく */
  .preview-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .preview-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  .preview-actions button {
    width: 100%;
    min-width: 0;
    padding: 12px 16px;
  }

  .radios-vertical .radio {
    padding: 12px 14px;
  }

  /* プレビュー領域はやや低めにして操作部を確保 */
  #pdfFrame,
  #pdfFrameQuiz,
  #pdfFrameAnswers {
    height: 65vh;
  }

  /* カスタムセレクトのリスト高さを画面に収める */
  .select-list {
    max-height: min(50vh, 260px);
  }

  /* フッターは縦配置で中央寄せ */
  .footer-inner {
    flex-direction: column;
    gap: 6px;
    text-align: center;
  }
}

/* さらに狭い端末での微調整 */
@media (max-width: 400px) {
  .brand {
    font-size: 1.1rem;
  }
  .preview-actions {
    grid-template-columns: 1fr;
  }
}

/* Additional utility classes */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus improvements for accessibility */
*:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* Skip link for keyboard users */
.skip-link {
  position: absolute;
  left: 8px;
  top: -40px;
  padding: 10px 14px;
  background: var(--brand-gradient);
  color: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow-brand);
  transition: top 0.15s ease;
  z-index: 100000;
}
.skip-link:focus {
  top: 8px;
}

/* Select search */
.select-search {
  position: absolute;
  z-index: 10002;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 12px 12px 0 0;
  box-shadow: var(--shadow-lg);
}
.select-custom .select-search {
  display: none;
}
.select-custom.open .select-search {
  display: block;
}
.select-search input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--line);
  background: var(--elev-2);
  color: var(--text);
  font-size: 0.95rem;
}
.select-search input[type="text"]:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--ring), var(--shadow-sm);
}

/* Make the list attach to the search box seamlessly */
.select-custom .select-list {
  margin-top: 48px; /* height of search area incl. paddings */
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
