/* No pull-to-refresh (Chrome / Samsung Internet, browser tab or installed
   app): a vigorous downward tap-drag mid-test must not reload the page.
   Ordinary scrolling of long screens is unaffected. */
html, body {
  overscroll-behavior-y: none;
}

body {
  font-family: sans-serif;
  text-align: center;
  margin: 0;
  padding: 0;
  background-color: #ffffff; /* UC white background */
  color: #000000;
}

.screen {
  display: none;
  padding: 1rem;
}

.branding {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin: 2rem 0 1rem 0;
}

.uc-logo {
  height: 60px;
  width: auto;
}

.afc-text {
  font-size: 4rem;
  font-weight: bold;
  color: #000000; /* UC red */
  text-transform: uppercase;
  letter-spacing: 1px;
}
.grid-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: calc(100vh - 8rem); /* Leave some breathing space */
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
  width: min(90vw, 90vh);     /* Square box that fits screen */
  height: min(90vw, 90vh);
  box-sizing: border-box;
}

.grid > div {
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.grid img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: opacity 0.2s ease;
  cursor: pointer;
}


input,
button,
select {
  font-size: 1rem;
  margin: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  border: 1px solid #ccc;
}

button {
  background-color: #c8102e; /* UC red */
  color: white;
  border: none;
  cursor: pointer;
}

button:hover {
  background-color: #a00c25; /* darker UC red for hover */
}

#calibrateBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#loading-ok:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#training-img {
  max-width: 100%;
  object-fit: contain;
}

#abortBtn {
  display: none;
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 1000;
  width: 44px;
  height: 44px;
  padding: 0;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid #aaa;
  border-radius: 0.35em;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;     /* iOS Safari ignores the unprefixed form */
  -webkit-touch-callout: none;   /* no long-press callout / magnifier */
}
#abortBtn * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#abortBtn:hover { opacity: 0.9; }
#abortBtn svg {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
}
#abortBtn .abort-track { fill: none; stroke: #ddd; stroke-width: 3; }
#abortBtn .abort-progress {
  fill: none;
  stroke: #b31b1b;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 100.53;
  stroke-dashoffset: 100.53;
}
#abortBtn .abort-x {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.15rem;
  line-height: 1;
  color: #666;
  pointer-events: none;
}
#abortBtn.holding { opacity: 1; }
#abortBtn.holding .abort-x { color: #900; }


.footer {
  font-size: 0.75rem;
  color: #666;
  margin-top: 2rem;
  text-align: center;
}

.small {
  font-size: 0.8rem;
  color: grey;
  margin-top: 1rem;
}

h1, h2 {
  color: #c8102e; /* UC red headings */
}

img.disabled {
  opacity: 0.3;
  pointer-events: none;
}

#countdown {
  font-size: 2rem;
  text-align: center;
  margin-bottom: 1rem;
  color: #444;
  display: none;
}

/* ── Calibration panel (mirrors UC_CVCV) ── */
.volume-panel {
  margin: 1rem auto;
  padding: 0.9rem;
  max-width: 24rem;
  background: #f7f8f9;
  border: 1px solid #dde0e4;
  border-radius: 8px;
}
.volume-panel label {
  font-weight: 600;
  font-size: 0.9rem;
  color: #333;
}
.level-readout {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}
.level-readout strong {
  font-size: 1.2rem;
}
#modeBadge {
  font-size: 0.85rem;
  color: #666;
  padding: 0.15rem 0.5rem;
  border: 1px solid #dde0e4;
  border-radius: 6px;
  background: #fff;
}
#modeBadge.calibrated {
  color: #166534;
  border-color: #bbf7d0;
  background: #f0fdf4;
}
#testCalBtn[hidden] { display: none; }

/* ── Setup screen (adaptive controls) ── */
#setup { max-width: 42rem; margin: 0 auto; text-align: left; }
#setup h2 { text-align: center; }
.setup-block {
  border: 1px solid #dde0e4;
  border-radius: 8px;
  padding: 0.75rem 1rem 1rem;
  margin: 0.9rem 0;
  background: #fafafa;
}
.setup-label {
  display: block;
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #b31b1b;
  margin-bottom: 0.6rem;
}
.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem 1rem;
}
.setup-grid label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  color: #333;
  text-align: left;
  margin: 0;
}
.setup-grid input, .setup-grid select {
  width: 100%;
  margin-top: 0.25rem;
}
.setup-grid input[readonly] { background: #f0f0f0; color: #666; }
.setup-check {
  display: block;
  margin-top: 0.6rem;
  font-size: 0.88rem;
  font-weight: 600;
}
.setup-check input { width: auto; margin-right: 0.4rem; }
.segmented {
  display: inline-flex;
  border: 1px solid #c5cee0;
  border-radius: 999px;
  padding: 0.2rem;
  gap: 0.2rem;
  background: #fff;
}
.seg-btn {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #33415c;
  padding: 0.45rem 1.1rem;
  font-weight: 700;
  cursor: pointer;
}
.seg-btn.active { background: #b31b1b; color: #fff; }
@media (max-width: 560px) {
  .setup-grid { grid-template-columns: 1fr; }
}

/* Normalisation: per-word level plan */
[hidden] { display: none !important; }
.cs-plan { text-align: left; margin-bottom: 0.6rem; }
.cs-filebtn {
  display: inline-block; position: relative; overflow: hidden;
  background: #b31b1b; color: #fff; font-weight: 700; font-size: 0.9rem;
  border-radius: 6px; padding: 0.45rem 0.9rem; cursor: pointer;
}
.cs-filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.cs-filebtn:focus-within { outline: 2px solid #33415c; outline-offset: 2px; }
.cs-plan-clear { background: #777; font-size: 0.9rem; padding: 0.45rem 0.9rem; margin-left: 0.3rem; }
#csPlanText {
  display: block; width: 100%; box-sizing: border-box; margin-top: 0.5rem;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.78rem; line-height: 1.4;
  tab-size: 9; white-space: pre; overflow-x: auto; padding: 0.5rem; border: 1px solid #c5cee0; border-radius: 6px;
}
.cs-plan-check { font-size: 0.85rem; margin: 0.35rem 0 0.5rem; display: grid; gap: 0.15rem; text-align: left; }
.cs-source .seg-btn { padding: 0.45rem 0.7rem; white-space: nowrap; font-size: 0.9rem; }
.cs-central-show { margin-top: 0.5rem; font-size: 0.85rem; }
.cs-central-show summary { cursor: pointer; font-weight: 600; }
#csCentralText {
  margin: 0.4rem 0 0; max-height: 14rem; overflow: auto; padding: 0.5rem; border: 1px solid #c5cee0; border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.75rem; line-height: 1.4; tab-size: 9; white-space: pre; background: #f7f8fb;
}
.cs-plan-check .err { color: #b31b1b; }
.cs-plan-check .warn { color: #8a5a00; }
.cs-plan-check .ok { color: #1d6b1d; }
/* Word normalisation table (Setup and Constant stimuli) */
.norm-text {
  display: block; width: 100%; box-sizing: border-box; margin-top: 0.5rem;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.78rem; line-height: 1.4;
  tab-size: 9; white-space: pre; overflow-x: auto; padding: 0.5rem; border: 1px solid #c5cee0; border-radius: 6px;
}
.norm-pre {
  margin: 0.4rem 0 0; max-height: 14rem; overflow: auto; padding: 0.5rem; border: 1px solid #c5cee0; border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.75rem; line-height: 1.4; tab-size: 9; white-space: pre; background: #f7f8fb;
}
/* Keep the normalisation screen's fields inside a phone-width screen. */
#conststim input[type="text"], #conststim input[type="number"] { box-sizing: border-box; max-width: 100%; }
@media (max-width: 400px) { .cs-source .seg-btn { padding: 0.45rem 0.55rem; font-size: 0.85rem; } }
@media (max-width: 360px) { .cs-source .seg-btn { white-space: normal; } }

/* Form fields never stick out of their boxes (width: 100% now includes the
   padding and border), on every screen and at any width. */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea {
  box-sizing: border-box;
  max-width: 100%;
}
canvas { max-width: 100%; }
.segmented { max-width: 100%; flex-wrap: wrap; justify-content: center; }
label > input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), label > select {
  margin-left: 0;
  margin-right: 0;
}
