/* ================================
   iOS-style unified stylesheet
   (deduplicated + consolidated)
   ================================ */

/* ---------- Theme variables ---------- */
:root {
  color-scheme: light dark;
  --ios-blue: #0a84ff;
  --text: #111315;
  --text-dim: #5c5f62;
  --bg: #f5f5f7;
  --hairline: rgba(60,60,67,0.29);
  --surface: rgba(255,255,255,0.72);
  --surface-strong: rgba(255,255,255,0.88);
  --surface-weak: rgba(118,118,128,0.12);
  --shadow: 0 0.5px 0.5px rgba(0,0,0,.10), 0 8px 24px rgba(0,0,0,.12);
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;

  /* spacing */
  --space-xs: 6px;
  --space-sm: 12px;
  --space-md: 20px;
  --space-lg: 32px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #f2f2f7;
    --text-dim: #b1b2b7;
    --bg: #1c1c1e;
    --surface: rgba(28,28,30,0.65);
    --surface-strong: rgba(44,44,46,0.7);
    --surface-weak: rgba(118,118,128,0.20);
    --hairline: rgba(255,255,255,0.18);
    --shadow: 0 0.5px 0.5px rgba(0,0,0,.30), 0 10px 28px rgba(0,0,0,.35);
  }
}

/* ---------- Base layout & typography ---------- */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 10% -10%, #eaf0ff 0%, transparent 50%),
    radial-gradient(900px 600px at 110% 0%, #ffeef2 0%, transparent 55%),
    var(--bg) !important;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  background: var(--surface);
  border-bottom: 0.5px solid var(--hairline);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand {
  font-weight: 700;
  letter-spacing: -0.015em;
}
.lang-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

/* ---------- Container (card) ---------- */
.container {
  background: var(--surface-strong) !important;
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg) !important;
  box-shadow: var(--shadow);
  padding: 28px !important; /* unified */
  max-width: 720px;
  margin: 18px auto;
}

/* ---------- Headings & notes ---------- */
h1, h2, h3 { letter-spacing: -0.01em; margin: 0.25em 0; }
h1 { font-weight: 800; font-size: 1.75rem; }
h2 { font-weight: 700; font-size: 1.2rem; }
.note { color: var(--text-dim) !important; }

/* Large Title */
.large-title {
  font-family: -apple-system, "SF Pro Display", system-ui, "Segoe UI", Roboto, Arial;
  font-weight: 800;
  font-size: clamp(28px, 5vw, 36px);
  letter-spacing: -0.02em;
  line-height: 1.08;
  margin: 8px 0 14px 0;
}
.large-subtitle {
  color: var(--text-dim);
  margin-top: -6px;
  margin-bottom: 12px;
  font-size: 0.98rem;
}

/* ---------- Forms ---------- */
input[type="text"], input[type="number"], select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  outline: none;
  transition: box-shadow .2s ease, border-color .2s ease;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus {
  border-color: rgba(10,132,255,.6);
  box-shadow: 0 0 0 4px rgba(10,132,255,.12);
}
.lang-switch select {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 140px;
}

/* form layout helpers */
.form-row { margin-bottom: var(--space-md) !important; }

/* ---------- Buttons ---------- */
button {
  font: inherit;
  cursor: pointer;
  border: none;
}
.primary {
  background: var(--ios-blue) !important;
  color: #fff !important;
  border: none !important;
  border-radius: 14px !important;
  padding: 12px 16px !important;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(10,132,255,.28);
  transition: transform .06s ease, filter .2s ease, box-shadow .2s ease;
}
.primary:hover { filter: saturate(110%); }
.primary:active { transform: translateY(1px) scale(0.98); box-shadow: 0 1px 4px rgba(10,132,255,.24); }

.secondary {
  background: var(--surface-weak) !important;
  color: var(--text) !important;
  border: 1px solid var(--hairline) !important;
  border-radius: 12px !important;
  padding: 10px 14px !important;
}

/* ---------- Table ---------- */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.table th, .table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--hairline);
}
.table thead th {
  background: var(--surface-strong);
  text-align: left;
  font-weight: 700;
}
.table tr:last-child td { border-bottom: none; }

/* ---------- Utilities: spacing & stacks ---------- */
.spacer-xs{ height: var(--space-xs); }
.spacer-sm{ height: var(--space-sm); }
.spacer-md{ height: var(--space-md); }
.spacer-lg{ height: var(--space-lg); }

.stack{
  display:flex;
  flex-direction:column;
  gap: var(--space-md);
}

/* ---------- Progress / badges ---------- */
.progress-row { display:flex; align-items:center; justify-content:center; gap: var(--space-sm); }
#progress {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  font-size: 0.95rem;
}

/* ---------- Test page centered layout ---------- */
.test-page{
  display: grid;
  justify-items: center;
  row-gap: 14px;
}
.test-page #condTitle,
.test-page #condText,
.test-page .progress-row,
.test-page #statusMsg,
.test-page #playHint{ text-align:center; }
.test-page .audiocontrol{
  display:flex; flex-direction:column; align-items:center; gap:8px;
}
#playTrial, #nextConditionBtn{ display:inline-flex; margin:0 auto; }
.test-page .keypad{ margin:10px auto 0 auto !important; }

/* ---------- Keypad ---------- */
.keypad { max-width: 380px !important; }
.kp-row { display:flex; justify-content:center; gap:12px; margin:10px 0 !important; }

/* unified keypad button size/appearance */
.keypad-button{
  width: 78px;
  height: 64px;
  font-size: 24px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border-radius: 14px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(0,0,0,0.04), 0 6px 18px rgba(0,0,0,0.06);
  transition: transform .06s ease, background .2s ease;
}
.keypad-button:hover { background: var(--surface-strong); }
.keypad-button:active { transform: scale(0.98); }

/* OK uses same system blue as primary buttons */
.keypad-button.primary{
  background: var(--ios-blue) !important;
  border-color: var(--ios-blue) !important;
  color: #fff !important;
}

/* Backspace SVG: single, consistent size + look */
#clear.keypad-button svg{
  width: 26px;
  height: 26px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#clear::before { content: none !important; } /* ensure no '⌫' from pseudo */

/* ---------- Input digit boxes (horizontal) ---------- */
#input.display-box{
  display: flex !important;
  flex-direction: row !important;
  justify-content: center !important;
  align-items: center !important;
  flex-wrap: nowrap !important;
  gap: 12px !important;
  width: auto !important;
  max-width: none !important;
  margin: 6px auto 0 auto !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  min-height: 64px !important;
}
#input.display-box .digit-box{
  width: 54px; height: 64px;
  display: inline-flex !important;
  align-items: center; justify-content: center;
  border: 1px solid var(--hairline);
  border-radius: 16px;
  background: var(--surface-strong);
  font-size: 26px; font-weight: 700;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,0.04), 0 8px 18px rgba(0,0,0,0.06);
}

/* ---------- Motion preference ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* 只让 OK 的字更小（不改按钮尺寸） */
#ok.keypad-button { 
  font-size: 18px;   /* 你想要的字号，比如 16~18px */
  font-weight: 700;  /* 可保留粗细，也可改成 600 */
  letter-spacing: 0.02em; /* 视情况微调字距 */
}

/* === keypad 禁用态（播放中） === */
.keypad.disabled .keypad-button,
.keypad-button.disabled {
  pointer-events: none;
  filter: grayscale(100%);
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

/* 播放按钮禁用态（可选） */
#playTrial.disabled, #playTrial:disabled {
  pointer-events: none;
  opacity: 0.5;
  cursor: not-allowed;
}
