@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Bebas+Neue&family=Space+Mono:wght@400;700&display=swap');

:root {
  --bg: #0a0a0b;
  --surface: #111114;
  --surface-strong: #151518;
  --border: #2a2a30;
  --gold: #c9a84c;
  --gold-glow: #e8c55a;
  --gold-dim: #6b5520;
  --green: #b8ff4a;
  --text: #d4c9a8;
  --text-dim: #5a5545;
  --line: #252530;
  --danger: #ff6b6b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  background:
    radial-gradient(circle at top, rgba(201, 168, 76, 0.08), transparent 32%),
    linear-gradient(180deg, #0a0a0b 0%, #09090a 100%);
  color: var(--text);
  font-family: 'Space Mono', monospace;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  appearance: none;
}

button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

main {
  min-height: 100dvh;
}

.screen {
  display: none;
  width: 100%;
  height: 100dvh;
}

.screen.active {
  display: flex;
}

#screen-intro {
  align-items: center;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  padding: 32px 20px;
  position: relative;
}

.intro-bg {
  background: radial-gradient(ellipse 60% 60% at 50% 30%, rgba(201, 168, 76, 0.06) 0%, transparent 70%);
  inset: 0;
  pointer-events: none;
  position: fixed;
}

.morse-diagram {
  margin-bottom: 28px;
  max-width: 360px;
  position: relative;
  width: 100%;
}

.morse-diagram svg {
  height: auto;
  overflow: visible;
  width: 100%;
}

#treeSvg > .tree-line,
#treeSvg > .node-dot,
#treeSvg > .letter-label,
#appTreeSvg > .tree-line {
  display: none;
}

.node-dot {
  fill: #1c1c22;
  stroke: #3a3a45;
  stroke-width: 1.5;
  transition: fill 0.3s, filter 0.3s, stroke 0.3s, opacity 0.2s;
}

.node-dot.path-node {
  fill: rgba(201, 168, 76, 0.28);
  stroke: var(--gold-dim);
}

.node-dot.lit {
  fill: var(--gold);
  filter: drop-shadow(0 0 8px var(--gold-glow));
  stroke: var(--gold-glow);
}

.letter-label {
  fill: var(--text-dim);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 14px;
  letter-spacing: 1px;
  transition: fill 0.3s, opacity 0.2s;
}

.letter-label.path-label {
  fill: rgba(201, 168, 76, 0.76);
}

.letter-label.lit {
  fill: var(--gold-glow);
  filter: drop-shadow(0 0 4px var(--gold));
}

.tree-line {
  stroke: var(--line);
  stroke-linecap: round;
  stroke-width: 1.5;
}

.decoder-line {
  stroke-width: 2;
}

.intro-content {
  max-width: 460px;
  text-align: center;
  width: 100%;
}

.brand {
  color: var(--gold-dim);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 11px;
  letter-spacing: 6px;
  margin-bottom: 16px;
}

.brand-inline {
  margin-bottom: 8px;
}

.gold-inline {
  color: var(--gold);
}

.welcome-text {
  color: var(--text);
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(28px, 6vw, 48px);
  line-height: 1.1;
  margin-bottom: 8px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.8s, transform 0.8s;
}

.welcome-text.visible {
  opacity: 1;
  transform: translateY(0);
}

.welcome-sub {
  color: var(--text-dim);
  font-size: 12px;
  letter-spacing: 2px;
  margin-bottom: 40px;
  opacity: 0;
  transition: opacity 0.8s 0.4s;
}

.welcome-sub.visible {
  opacity: 1;
}

.start-btn {
  background: none;
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  cursor: pointer;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 18px;
  letter-spacing: 4px;
  overflow: hidden;
  padding: 14px 40px;
  position: relative;
  transition: border-color 0.3s, color 0.3s, box-shadow 0.3s;
}

.start-btn:hover {
  border-color: var(--gold);
  box-shadow: 0 0 20px rgba(201, 168, 76, 0.15);
  color: var(--gold-glow);
}

#screen-app {
  align-items: center;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(10px, env(safe-area-inset-bottom));
  position: relative;
  -webkit-overflow-scrolling: touch;
}

.top-bar {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-shrink: 0;
  justify-content: space-between;
  margin-bottom: 8px;
  max-width: 640px;
  padding-bottom: 8px;
  width: 100%;
}

.logo {
  color: var(--gold);
  font-family: 'Space Mono', monospace;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 2px;
}

.logo-button {
  background: none;
  border: 0;
  cursor: pointer;
  padding: 0;
  text-align: left;
  transition: color 0.2s, text-shadow 0.2s;
}

.logo-button:hover,
.logo-button:focus-visible {
  color: var(--gold-glow);
  outline: none;
  text-shadow: 0 0 12px rgba(232, 197, 90, 0.28);
}

.task-counter {
  color: var(--text-dim);
  font-size: 10px;
  letter-spacing: 3px;
}

.top-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.task-area {
  flex-shrink: 0;
  margin-bottom: 8px;
  max-width: 640px;
  width: 100%;
}

.task-phase {
  color: var(--gold-dim);
  font-size: 9px;
  letter-spacing: 4px;
  margin-bottom: 4px;
}

.task-prompt {
  color: var(--text);
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(16px, 3.5vw, 22px);
  line-height: 1.2;
  margin-bottom: 2px;
}

.target-word {
  align-items: baseline;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}

.target-char,
.target-space {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(24px, 5vw, 32px);
  position: relative;
  transition: color 0.3s;
}

.target-char {
  color: var(--text-dim);
}

.target-char.done {
  color: var(--gold);
}

.target-char.current {
  color: var(--text);
}

.target-char.current::after {
  animation: blink 1s infinite;
  background: var(--gold);
  bottom: -3px;
  content: '';
  height: 2px;
  left: 0;
  position: absolute;
  right: 0;
}

.target-space {
  color: transparent;
  min-width: 12px;
}

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

.diagram-panel {
  background: rgba(17, 17, 20, 0.88);
  border: 1px solid var(--border);
  display: flex;
  flex: 1 0 clamp(170px, 34dvh, 300px);
  flex-direction: column;
  margin-bottom: 8px;
  max-width: 640px;
  min-height: 170px;
  padding: 8px 10px;
  position: relative;
  width: 100%;
}

.diagram-panel svg {
  flex: 1;
  min-height: 130px;
  width: 100%;
}

.panel-label {
  color: var(--text-dim);
  flex-shrink: 0;
  font-size: 9px;
  letter-spacing: 4px;
  margin-bottom: 6px;
}

.mode-toggle-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.mode-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 9px;
  letter-spacing: 2px;
  padding: 5px 12px;
  transition: all 0.2s;
}

.mode-btn.active {
  background: rgba(201, 168, 76, 0.05);
  border-color: var(--gold-dim);
  color: var(--gold);
}

.morse-hint {
  align-items: center;
  background: rgba(17, 17, 20, 0.88);
  border: 1px solid var(--border);
  display: flex;
  flex-shrink: 0;
  gap: 12px;
  margin-bottom: 8px;
  max-width: 640px;
  min-height: 38px;
  padding: 8px 12px;
  width: 100%;
}

.hint-label {
  color: var(--text-dim);
  flex-shrink: 0;
  font-size: 9px;
  letter-spacing: 3px;
  white-space: nowrap;
}

.hint-code {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.hint-sym {
  align-items: center;
  display: flex;
  justify-content: center;
}

.hint-dot {
  background: var(--gold-dim);
  border-radius: 50%;
  height: 7px;
  width: 7px;
}

.hint-dash {
  background: var(--gold-dim);
  border-radius: 3px;
  height: 7px;
  width: 18px;
}

.hint-sym.active .hint-dot,
.hint-sym.active .hint-dash {
  background: var(--gold);
  box-shadow: 0 0 8px rgba(201, 168, 76, 0.5);
}

.hint-letter {
  color: var(--text-dim);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 13px;
  margin-left: 4px;
}

.hint-easy-status {
  color: var(--green);
  font-size: 9px;
  letter-spacing: 2px;
  margin-left: auto;
  opacity: 0;
  transition: opacity 0.2s;
}

.hint-easy-status.visible {
  opacity: 1;
}

.input-display {
  flex-shrink: 0;
  margin-bottom: 8px;
  max-width: 640px;
  width: 100%;
}

.signal-line {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 4px;
  min-height: 20px;
}

.sig-dot {
  animation: pop 0.1s ease;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--gold);
  height: 8px;
  width: 8px;
}

.sig-dash {
  animation: pop 0.1s ease;
  background: var(--gold);
  border-radius: 4px;
  box-shadow: 0 0 6px var(--gold);
  height: 8px;
  width: 22px;
}

@keyframes pop {
  from {
    transform: scale(0.6);
  }
  to {
    transform: scale(1);
  }
}

.decoded-text {
  color: var(--text-dim);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 22px;
  letter-spacing: 5px;
  line-height: 1;
  min-height: 28px;
}

.decoded-text .char-ok {
  color: var(--gold);
}

.decoded-text .char-err {
  color: var(--danger);
}

.key-section {
  align-items: center;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: 8px;
  max-width: 640px;
  width: 100%;
}

.key-instructions {
  display: flex;
  gap: 28px;
}

.key-inst {
  align-items: center;
  color: var(--text-dim);
  display: flex;
  font-size: 10px;
  gap: 6px;
  letter-spacing: 2px;
}

.key-inst-sym {
  align-items: center;
  display: flex;
}

.demo-dot {
  background: var(--gold);
  border-radius: 50%;
  height: 8px;
  margin-right: 6px;
  width: 8px;
}

.demo-dash {
  background: var(--gold);
  border-radius: 4px;
  height: 8px;
  margin-right: 6px;
  width: 22px;
}

.morse-key {
  -webkit-tap-highlight-color: transparent;
  background: radial-gradient(circle at 35% 30%, #2a2a30, #111114);
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  height: 80px;
  outline: none;
  position: relative;
  touch-action: none;
  transition: border-color 0.08s, box-shadow 0.08s;
  user-select: none;
  width: 80px;
}

.morse-key::before {
  background: radial-gradient(circle at 35% 30%, #1e1e24, #0d0d10);
  border: 1px solid var(--border);
  border-radius: 50%;
  content: '';
  inset: 7px;
  position: absolute;
  transition: background 0.1s;
}

.morse-key::after {
  color: var(--gold-dim);
  content: '●';
  display: flex;
  font-size: 22px;
  inset: 0;
  justify-content: center;
  position: absolute;
  text-shadow: 0 0 0 transparent;
  transition: color 0.1s, text-shadow 0.1s;
  z-index: 1;
}

.morse-key.pressed {
  border-color: var(--gold);
  box-shadow: 0 0 28px rgba(201, 168, 76, 0.4), inset 0 2px 10px rgba(0, 0, 0, 0.6);
}

.morse-key.pressed::before {
  background: radial-gradient(circle at 35% 30%, #252530, #0a0a0d);
}

.morse-key.pressed::after {
  color: var(--gold);
  text-shadow: 0 0 20px var(--gold-glow);
}

.kb-hint {
  color: var(--text-dim);
  font-size: 9px;
  letter-spacing: 2px;
  text-align: center;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding-bottom: 1px;
}

.action-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 10px;
  letter-spacing: 2px;
  padding: 6px 16px;
  transition: border-color 0.2s, color 0.2s, background 0.2s, box-shadow 0.2s;
}

.action-btn:hover {
  border-color: var(--gold-dim);
  color: var(--gold);
}

.action-btn.primary {
  border-color: var(--gold-dim);
  color: var(--gold);
}

.action-btn.primary:hover {
  border-color: var(--gold);
  box-shadow: 0 0 12px rgba(201, 168, 76, 0.15);
}

.speed-btn {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 13px;
  letter-spacing: 1px;
  min-width: 36px;
}

.speed-btn.active-speed {
  border-color: var(--gold-dim);
  color: var(--gold);
}

.easy-btn {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 13px;
  letter-spacing: 1px;
  min-width: 56px;
}

.easy-btn.active-easy {
  background: rgba(184, 255, 74, 0.06);
  border-color: var(--green);
  box-shadow: 0 0 8px rgba(184, 255, 74, 0.1);
  color: var(--green);
}

.easy-indicator {
  background: var(--green);
  box-shadow: 0 0 8px rgba(184, 255, 74, 0.5);
  display: none;
  height: 2px;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
}

body.easy-mode .easy-indicator {
  display: block;
}

body.easy-mode .morse-hint {
  border-color: rgba(184, 255, 74, 0.2);
}

@keyframes commitFlash {
  0% {
    background: rgba(184, 255, 74, 0.15);
  }
  100% {
    background: transparent;
  }
}

.letter-commit-flash {
  animation: commitFlash 0.3s ease forwards;
}

.wave-container {
  align-items: center;
  display: flex;
  gap: 3px;
  height: 20px;
  margin-bottom: 4px;
}

.wave-container[hidden] {
  display: none;
}

.wave-bar {
  animation: wave 1.2s ease infinite;
  background: var(--gold-dim);
  border-radius: 2px;
  width: 2px;
}

@keyframes wave {
  0%,
  100% {
    height: 3px;
  }
  50% {
    background: var(--gold);
    height: 14px;
  }
}

.progress-bar-wrap {
  background: var(--border);
  flex-shrink: 0;
  height: 2px;
  margin-bottom: 8px;
  max-width: 640px;
  width: 100%;
}

.progress-bar-fill {
  background: var(--gold);
  height: 100%;
  transition: width 0.5s ease;
}

.callsign-badge {
  background: rgba(17, 17, 20, 0.88);
  border: 1px solid var(--gold-dim);
  display: inline-block;
  margin-top: 4px;
  padding: 5px 16px;
}

.callsign-badge span {
  color: var(--gold);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 22px;
  letter-spacing: 6px;
}

.feedback-toast {
  background: rgba(17, 17, 20, 0.94);
  border: 1px solid;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 18px;
  left: 50%;
  letter-spacing: 4px;
  opacity: 0;
  padding: 10px 24px;
  pointer-events: none;
  position: fixed;
  top: 16px;
  transform: translateX(-50%);
  transition: opacity 0.3s;
  z-index: 100;
}

.feedback-toast.show {
  opacity: 1;
}

.feedback-toast.good {
  background: rgba(184, 255, 74, 0.05);
  border-color: var(--green);
  box-shadow: 0 0 20px rgba(184, 255, 74, 0.1);
  color: var(--green);
}

.feedback-toast.bad {
  background: rgba(255, 107, 107, 0.05);
  border-color: var(--danger);
  color: var(--danger);
}

#screen-tasks {
  align-items: center;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px 16px 40px;
}

.tasks-header {
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  max-width: 640px;
  padding-bottom: 14px;
  width: 100%;
}

.tasks-header-row {
  align-items: flex-start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.tasks-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.task-logo {
  display: inline-block;
  margin-bottom: 8px;
}

.tasks-header h1 {
  color: var(--text);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 36px;
  letter-spacing: 6px;
}

.tasks-header p {
  color: var(--text-dim);
  font-size: 10px;
  letter-spacing: 3px;
  margin-top: 4px;
}

.task-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 640px;
  width: 100%;
}

.custom-practice {
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  max-width: 640px;
  padding-bottom: 16px;
  width: 100%;
}

.custom-label,
.custom-help {
  color: var(--text-dim);
  font-size: 9px;
  letter-spacing: 3px;
}

.custom-label {
  display: block;
  margin-bottom: 8px;
}

.custom-input-row {
  display: flex;
  gap: 8px;
}

.custom-input {
  background: rgba(17, 17, 20, 0.88);
  border: 1px solid var(--border);
  color: var(--text);
  flex: 1;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  letter-spacing: 2px;
  min-width: 0;
  padding: 9px 12px;
  text-transform: uppercase;
}

.custom-input::placeholder {
  color: var(--text-dim);
}

.custom-input:focus {
  border-color: var(--gold-dim);
  outline: none;
  box-shadow: 0 0 12px rgba(201, 168, 76, 0.08);
}

.custom-help {
  margin-top: 7px;
}

.task-category {
  color: var(--gold-dim);
  font-size: 9px;
  letter-spacing: 4px;
  margin-bottom: 3px;
  margin-top: 14px;
}

.task-item {
  align-items: center;
  background: rgba(17, 17, 20, 0.88);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  gap: 14px;
  padding: 12px 16px;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.task-item:hover {
  background: var(--surface-strong);
  border-color: var(--gold-dim);
  transform: translateY(-1px);
}

.task-item.completed {
  border-color: var(--gold-dim);
}

.task-num {
  color: var(--text-dim);
  flex-shrink: 0;
  font-size: 10px;
  letter-spacing: 2px;
  width: 22px;
}

.task-word {
  color: var(--text);
  flex: 1;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 20px;
  letter-spacing: 4px;
}

.task-morse {
  color: var(--text-dim);
  flex-shrink: 0;
  font-size: 10px;
  letter-spacing: 1px;
}

.task-status {
  background: var(--border);
  border-radius: 50%;
  flex-shrink: 0;
  height: 7px;
  width: 7px;
}

.task-status.done {
  background: var(--gold);
  box-shadow: 0 0 5px var(--gold);
}

.code-grid {
  display: grid;
  flex: 1;
  gap: 6px;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  min-height: 0;
  overflow-y: auto;
}

.code-cell {
  -webkit-tap-highlight-color: transparent;
  background: rgba(17, 17, 20, 0.88);
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 8px 6px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}

.code-cell:hover {
  background: #161619;
  border-color: var(--gold-dim);
}

.code-cell.playing {
  background: rgba(201, 168, 76, 0.08);
  border-color: var(--gold);
  box-shadow: 0 0 12px rgba(201, 168, 76, 0.15);
}

.code-cell.played {
  background: rgba(201, 168, 76, 0.12);
  border-color: var(--gold);
}

.code-cell-letter {
  color: var(--gold);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 18px;
  letter-spacing: 2px;
  line-height: 1;
  margin-bottom: 5px;
}

.code-cell.playing .code-cell-letter {
  color: var(--gold-glow);
}

.code-cell-symbols {
  align-items: center;
  display: flex;
  gap: 3px;
  justify-content: center;
  min-height: 10px;
}

.csym {
  background: var(--text-dim);
  border-radius: 3px;
  display: inline-block;
  opacity: 0.5;
  transition: background 0.05s, opacity 0.05s, box-shadow 0.05s;
}

.cdot {
  border-radius: 50%;
  height: 6px;
  width: 6px;
}

.cdash {
  height: 6px;
  width: 14px;
}

.csym.playing-sym {
  background: var(--gold);
  box-shadow: 0 0 6px var(--gold);
  opacity: 1;
}

@media (max-width: 520px) {
  .tasks-header-row,
  .custom-input-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .tasks-actions,
  .custom-input-row,
  .custom-input,
  .custom-input-row .action-btn {
    width: 100%;
  }

  .tasks-actions {
    justify-content: flex-start;
  }

  .task-morse {
    display: none;
  }
}

@media (max-height: 680px) {
  #screen-app {
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .top-bar,
  .task-area,
  .diagram-panel,
  .morse-hint,
  .input-display {
    margin-bottom: 6px;
  }

  .key-section {
    gap: 6px;
  }

  .key-instructions {
    gap: 18px;
  }

  .morse-key {
    height: 72px;
    width: 72px;
  }
}

@media (max-height: 600px) {
  .diagram-panel {
    flex-basis: 150px;
    min-height: 150px;
  }

  .diagram-panel svg {
    min-height: 110px;
  }

  .kb-hint {
    display: none;
  }
}

@media (max-width: 400px) {
  .morse-key {
    height: 72px;
    width: 72px;
  }

  .key-instructions {
    gap: 18px;
  }

  .action-row {
    gap: 6px;
  }

  .action-btn {
    letter-spacing: 1.5px;
    padding: 6px 10px;
  }

  .easy-btn {
    min-width: 50px;
  }

  .target-char,
  .target-space {
    font-size: 22px;
  }
}
