:root {
  --bg: #0f1115;
  --fg: #e8eaed;
  --muted: #9aa0a6;
  --accent: #5e97ff;
  --success: #34c759;
  --danger: #ff4d4f;          /* high-contrast red for warnings */
  --danger-strong: #d32f2f;   /* solid red for critical background */
  --on-danger: #ffffff;       /* text on red */
  --intro-on: #0f1115;        /* text on intro */
  --gap: clamp(8px, 1.2vw, 16px);
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

/* Safe area support (iOS notch) */
.safe {
  padding: calc(env(safe-area-inset-top) + var(--gap))
           calc(env(safe-area-inset-right) + var(--gap))
           calc(env(safe-area-inset-bottom) + var(--gap))
           calc(env(safe-area-inset-left) + var(--gap));
  height: 100%;
  box-sizing: border-box;
}

/* Two-column landscape layout */
.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
  gap: var(--gap);
  height: 100%;
}

/* Left: 5 words, one per row */
.words {
  display: grid;
  grid-template-rows: repeat(5, 1fr);
  gap: var(--gap);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: calc(var(--gap) * 1.25);
  background: rgba(255,255,255,0.02);
}

.word {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(6px, 0.8vh, 10px) clamp(10px, 1.2vw, 16px);
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  /* Scales with viewport height; larger on bigger screens */
  font-size: clamp(18px, 4vh, 44px);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.2px;
  position: relative;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: visible; /* allow enlarged hit area pseudo-element */
  transition: transform 120ms ease, background 200ms ease, color 200ms ease, opacity 200ms ease;
}

/* Slightly enlarge tappable area beyond the visual box (if supported) */
.word::before {
  content: "";
  position: absolute;
  inset: -8px;
}

.word.word--pressed {
  transform: scale(0.98);
  background: rgba(255,255,255,0.06);
}

.word.word--disabled,
.word[aria-disabled="true"] {
  color: var(--muted);
  opacity: 0.7;
  background: rgba(255,255,255,0.02);
}

/* Full-width strike-through across the word box */
.word.word--disabled::after,
.word[aria-disabled="true"]::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  top: 50%;
  height: 2px;
  background: rgba(255,255,255,0.35);
  transform: translateY(-50%);
  border-radius: 2px;
  pointer-events: none;
}

/* Right: header timer + giant counter */
.right {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: var(--gap);
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: clamp(8px, 1.2vh, 14px) clamp(12px, 1.6vw, 18px);
  background: rgba(255,255,255,0.02);
  transition: background 200ms ease, border-color 200ms ease, color 150ms ease;
}

.hud .label {
  font-size: clamp(14px, 2.2vh, 18px);
  color: var(--muted);
}

.hud .value {
  font-size: clamp(24px, 4.5vh, 36px);
  font-variant-numeric: tabular-nums; 
  transition: color 120ms ease;
}

/* Size the timer icon */
.hud .label svg {
  width: clamp(18px, 2.6vh, 24px);
  height: clamp(18px, 2.6vh, 24px);
  display: block;
}

/* Timer warning and critical states */
.hud.hud--warn .value { color: var(--danger); }
.hud.hud--warn .label { color: var(--danger); }
.hud.hud--critical {
  background: var(--danger-strong);
  border-color: rgba(255,255,255,0.12);
  color: var(--on-danger);
}
.hud.hud--critical .value { color: var(--on-danger); }
.hud.hud--critical .label { color: var(--on-danger); }

/* Timeout overlay */
.overlay {
  position: fixed;
  inset: 0;
  padding: calc(env(safe-area-inset-top) + var(--gap))
           calc(env(safe-area-inset-right) + var(--gap))
           calc(env(safe-area-inset-bottom) + var(--gap))
           calc(env(safe-area-inset-left) + var(--gap));
  display: grid;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
  text-align: center;
}
.overlay--visible {
  opacity: 1;
  pointer-events: auto;
}
.overlay__panel {
  align-self: stretch;
  justify-self: stretch;
  margin: 0; /* match main screen edge padding */
  border-radius: 14px;
  background: var(--danger-strong);
  color: var(--on-danger);
  display: grid;
  place-items: center;
}
.overlay__content {
  font-size: clamp(40px, 10vh, 120px);
  font-weight: 700;
  letter-spacing: -0.5px;
}

/* Start overlay theme */
.overlay--start .overlay__panel {
  background: linear-gradient(135deg, #effbe7 0%, #d4f7e2 50%, #e7f9ef 100%);
  color: var(--intro-on);
}
.overlay__title {
  font-size: clamp(36px, 9vh, 96px);
  font-weight: 800;
  margin-bottom: clamp(50px, 10vh, 70px);
}
.overlay__subtitle {
  font-size: clamp(28px, 4.5vh, 40px);
  font-weight: 500;
  opacity: 0.9;
  line-height: 150%;
}

.counter {
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  background: radial-gradient(120% 120% at 100% 0%, rgba(94,151,255,0.08), rgba(255,255,255,0.02));
  transition: background 200ms ease, border-color 200ms ease, color 150ms ease;
}

.counter .value {
  font-size: clamp(72px, 22vh, 240px);
  line-height: 1;
  font-weight: 700;
  letter-spacing: -1px;
  text-shadow: 0 6px 30px rgba(0,0,0,0.35);
  transition: color 120ms ease;
}

/* Counter warning and critical states */
.counter.counter--warn .value { color: var(--danger); }
.counter.counter--critical {
  background: var(--danger-strong);
  border-color: rgba(255,255,255,0.12);
  color: var(--on-danger);
}
.counter.counter--critical .value { color: var(--on-danger); }

/* Portrait: top 50% words, bottom 50% counter with timer at bottom */
@media (orientation: portrait) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr; /* halves */
  }
  .words {
    grid-template-rows: repeat(5, 1fr); /* fill top half evenly */
  }
  .counter .value {
    font-size: clamp(56px, 14vw, 160px);
  }
  /* Words sit in the top half, so use a gentler vh multiplier */
  .word {
    font-size: clamp(18px, 2.6vh, 36px);
  }
  /* Reflow the right side so the counter fills and timer sits below */
  .right {
    display: grid;
    grid-template-rows: 1fr auto; /* counter fills, timer at bottom */
    height: 100%;
    min-height: 0;
  }
  .right .counter { grid-row: 1; }
  .right .hud { grid-row: 2; align-self: stretch; }
}

/* Admin panel layout */
.admin-panel {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: var(--gap);
}

.admin-reset {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(14px, 2vh, 22px);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  appearance: none;
  background: rgba(255,255,255,0.02);
  border-radius: 14px;
  color: inherit;
  padding: clamp(8px, 1.2vh, 14px) clamp(12px, 1.6vw, 18px);
  border: 1px solid rgba(255,255,255,0.06);
  transition: background 200ms ease, border-color 200ms ease, color 150ms ease;
}

.admin-reset#reset-time-button {
  justify-content: space-between;
}

.admin-reset:hover {
  background: rgba(94,151,255,0.14);
  border-color: rgba(94,151,255,0.3);
}

.admin-reset:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.admin-counter {
  cursor: pointer;
  user-select: none;
}

.admin-counter:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.words--interpreter {
  height: 100%;
  display: grid;
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: calc(var(--gap) * 0.75);
  box-sizing: border-box;
}

.word--phrase {
  text-transform: none;
  line-height: 1.25;
  font-size: clamp(22px, min(3.8vh, 5vw), 38px);
  word-break: break-word;
}

@media (orientation: landscape) and (max-height: 600px) {
  .word--phrase {
    font-size: clamp(18px, 3vh, 28px);
  }
}

/* Music page */
.words--music {
  height: 100%;
}

.word--audio {
  position: relative;
  text-transform: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 6vw, 42px);
  padding-inline: clamp(18px, 6vw, 70px);
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease;
}

.word--audio__content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 5vw, 38px);
  pointer-events: none;
}

.word--audio__icon {
  font-size: clamp(28px, 4vh, 44px);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: clamp(32px, 4.2vh, 48px);
}

.word--audio__title {
  font-size: clamp(24px, 4vh, 40px);
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.word--audio__progress-wrapper {
  position: absolute;
  top: 50%;
  right: clamp(12px, 4vw, 28px);
  transform: translateY(-50%);
  width: clamp(140px, 32vw, 260px);
  display: flex;
  align-items: center;
  padding: clamp(10px, 2vh, 18px) 0;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 160ms ease;
}

.word--audio__progress {
  width: 100%;
  accent-color: var(--accent);
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  height: 28px;
}

.word--audio__progress:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.word--audio__progress::-webkit-slider-runnable-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.28);
  border-radius: 999px;
}

.word--audio__progress::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: -6px;
  box-shadow: 0 2px 8px rgba(94, 151, 255, 0.35);
}

.word--audio__progress::-moz-range-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.28);
  border-radius: 999px;
}

.word--audio__progress::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  box-shadow: 0 2px 8px rgba(94, 151, 255, 0.35);
}

.word--audio__progress::-ms-track {
  background: transparent;
  border-color: transparent;
  color: transparent;
  height: 6px;
}

.word--audio__progress::-ms-fill-lower,
.word--audio__progress::-ms-fill-upper {
  background: rgba(255, 255, 255, 0.28);
  border-radius: 999px;
}

.word--audio__progress::-ms-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
}

.word--audio[aria-pressed="true"] {
  background: rgba(94, 151, 255, 0.16);
  border-color: rgba(94, 151, 255, 0.3);
}

.word--audio[aria-pressed="true"] .word--audio__progress-wrapper {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

/* Navigation landing page */
.nav {
  height: 100%;
}


.nav__grid {
  display: grid;
  gap: calc(var(--gap) * 1.25);
  height: 100%;
  align-content: center;
  grid-auto-rows: minmax(clamp(128px, 22vh, 220px), auto);
}

.nav__row {
  display: grid;
  gap: var(--gap);
  grid-template-columns: minmax(220px, 2fr) repeat(2, minmax(150px, 1fr));
  align-items: stretch;
  padding: clamp(18px, 2vh, 28px);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.nav__title,
.nav__link.word {
  display: flex;
  align-items: center;
  padding: clamp(12px, 1.6vh, 20px) clamp(16px, 2vw, 28px);
  /* height: 100%; */
}

.nav__title {
  font-size: clamp(22px, 3.4vw, 40px);
  font-weight: 700;
  line-height: 1.15;
  color: var(--fg);
  text-transform: uppercase;
}

.nav__link {
  text-decoration: none;
  color: inherit;
}

.nav__link.word {
  justify-content: center;
  color: var(--muted);
  font-size: clamp(22px, 3.6vw, 36px);
  font-weight: 700;
  transition: color 140ms ease;
}

.nav__link.word:hover,
.nav__link.word:focus-visible {
  color: var(--fg);
}

.nav__link.word:active {
  color: var(--fg);
}

.nav__link.word.nav__link--launching {
  color: var(--fg);
  background: rgba(52, 199, 89, 0.32);
}

@media (max-width: 900px) {
  .nav__row {
    grid-template-columns: minmax(200px, 1.6fr) repeat(2, minmax(140px, 1fr));
  }
}

@media (max-width: 640px) {
  .nav__grid {
    align-content: start;
  }

  .nav__row {
    grid-template-columns: 1fr;
    padding: clamp(12px, 2vh, 22px);
  }

  .nav__title {
    height: auto;
    justify-content: center;
    text-align: center;
  }

  .nav__link.word {
    font-size: clamp(22px, 8vw, 32px);
    height: auto;
  }
}
