/* =========================================================
   Morse Trainer Web — Stylesheet
   ========================================================= */

/* --- Design tokens --- */
:root {
  --bg:        #1a1a1a;   /* very dark grey */
  --accent:    #ff4d00;   /* orange accent */
  --surface:   #e8e8e8;   /* very light grey — textbox & button */
  --text-on-surface: #111111;
  --font-sans: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* --- Reset --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* --- Full-viewport layout --- */
html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--surface);
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* =========================================================
   Header
   ========================================================= */
header {
  flex-shrink: 0;
  background-color: var(--bg);
  text-align: center;
  padding: 1.25rem 1rem;
}

header h1 {
  color: var(--accent);
  font-size: clamp(1.4rem, 3vw, 2.2rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* =========================================================
   Footer
   ========================================================= */
footer {
  flex-shrink: 0;
  background-color: var(--bg);
  text-align: center;
  padding: 0.9rem 1rem;
}

footer p {
  color: var(--accent);
  font-size: clamp(0.75rem, 1.4vw, 0.95rem);
  letter-spacing: 0.04em;
}

/* =========================================================
   Main content area
   ========================================================= */
main {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-color: var(--bg);
}

/* =========================================================
   Text box  (#textbox)
   ─ width  : 67% of main
   ─ height : 33% of main
   ─ vertical centre at 33% from top of main
     → top edge = 33% − 33%/2 = 16.5%
   ========================================================= */
#textbox {
  position: absolute;
  width: 67%;
  height: 33%;
  top: 16.5%;
  left: 50%;
  transform: translateX(-50%);

  background-color: var(--surface);
  color: var(--text-on-surface);
  border: none;
  border-radius: 8px;
  padding: 1.1rem 1.5rem;

  /* Font large enough for ~5 comfortable rows */
  font-size: clamp(0.85rem, 2.6vh, 1.2rem);
  line-height: 1.65;
  font-family: var(--font-sans);

  overflow-y: auto;
}

/* Placeholder state */
#textbox .placeholder {
  color: #888;
  font-style: italic;
  font-size: inherit;
}

/* Each content line */
#textbox .textbox-line {
  display: block;
  word-break: break-word;
}

/* Clickable source link */
#textbox .textbox-line a {
  color: #1a56db;
  text-decoration: underline;
  word-break: break-all;
}

#textbox .textbox-line a:hover {
  color: #1039a8;
}

/* =========================================================
   Learn/Test mode switch  (#mode-switch-container)
   ─ left-aligned with the left edge of #textbox
   ─ textbox left edge = 50% − 33.5% = 16.5% of main
   ─ sits just below the textbox bottom (49.5% of main)
   ========================================================= */
#mode-switch-container {
  position: absolute;
  top: calc(49.5% + 3vh);
  left: calc(50% - 33.5%);

  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}

.mode-label {
  color: var(--accent);
  font-size: clamp(0.85rem, 1.8vw, 1.05rem);
  font-weight: 600;
  letter-spacing: 0.03em;
}

/* Wrapper <label> — sized to contain the track */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Hide the native checkbox */
.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

/* The pill-shaped track */
.toggle-track {
  position: absolute;
  inset: 0;
  background: #555;
  border-radius: 11px;
  transition: background 0.18s;
}

/* The sliding thumb */
.toggle-track::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 2px;
  background: var(--surface);
  border-radius: 50%;
  transition: transform 0.18s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}

/* Checked (Test mode, default) — thumb slides right, track goes accent */
.toggle-switch input:checked + .toggle-track {
  background: var(--accent);
}

.toggle-switch input:checked + .toggle-track::before {
  transform: translateX(22px);
}

/* Disabled state during playback */
.toggle-switch input:disabled + .toggle-track {
  opacity: 0.45;
}

.toggle-switch:has(input:disabled) {
  cursor: not-allowed;
}

/* =========================================================
   Controls  (.controls)
   ─ horizontally centred
   ─ top edge: textbox bottom (49.5% of main) + 3vh gap
   ========================================================= */
.controls {
  position: absolute;
  top: calc(49.5% + 3vh);
  left: 50%;
  transform: translateX(-50%);

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
}

/* --- Speed slider group --- */
.slider-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
}

.slider-group label {
  color: var(--accent);
  font-size: clamp(0.85rem, 1.8vw, 1.05rem);
  font-weight: 600;
  letter-spacing: 0.03em;
  user-select: none;
}

#morse-speed-value {
  display: inline-block;
  min-width: 2.5ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Slider track styling */
#morse-speed {
  -webkit-appearance: none;
  appearance: none;
  width: clamp(180px, 30vw, 340px);
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--pct, 50%),   /* filled portion; updated by JS */
    #444 var(--pct, 50%),
    #444 100%
  );
  outline: none;
  cursor: pointer;
}

#morse-speed::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 4px rgba(0,0,0,0.4);
}

#morse-speed::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 4px rgba(0,0,0,0.4);
}

/* --- "Find an article" button --- */
#find-btn {
  width: 10vw;
  min-width: 120px;         /* readable on smaller screens */
  padding: 0.55em 0.6em;
  background-color: var(--surface);
  color: var(--text-on-surface);
  border: none;
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: clamp(0.8rem, 1.5vw, 1.05rem);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

#find-btn:hover {
  background-color: #d4d4d4;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}

#find-btn:active {
  background-color: #c0c0c0;
}

#find-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* =========================================================
   Responsive — best-effort for narrow viewports
   ========================================================= */
@media (max-width: 700px) {
  #textbox {
    width: 90%;
  }

  #find-btn {
    width: 40vw;
  }
}
