:root {
  --ink: #14202b;
  --ink-soft: #3a4a58;
  --paper: #e8eef3;
  --paper-2: #d5e0ea;
  --sea: #6a8fa8;
  --sea-deep: #2f5368;
  --signal: #e85d3a;
  --signal-deep: #c44728;
  --ok: #1f7a5c;
  --bad: #b33a3a;
  --line: rgba(20, 32, 43, 0.12);
  --radius: 4px;
  --font-body: "Noto Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  --font-mono: "Noto Sans Mono", ui-monospace, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.65;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
  color: inherit;
}

button:disabled,
input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Atmosphere */
.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.horizon {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 90% 55% at 50% -10%, #f4f8fb 0%, transparent 55%),
    linear-gradient(180deg, #c9d8e4 0%, #e8eef3 42%, #d7e4d8 100%);
}

.grid {
  position: absolute;
  inset: 0;
  opacity: 0.28;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.55), transparent 85%);
}

.noise {
  position: absolute;
  inset: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Header */
.site-header {
  padding: clamp(2rem, 8vw, 4.5rem) clamp(1.25rem, 5vw, 3rem) 1.25rem;
  max-width: 1100px;
  margin: 0 auto;
  animation: rise 0.8s var(--ease) both;
}

.brand {
  margin: 0;
  font-weight: 700;
  font-size: clamp(2rem, 7vw, 3.2rem);
  letter-spacing: 0.02em;
  line-height: 1.2;
  color: var(--ink);
}

.tagline {
  margin: 0.85rem 0 0;
  max-width: 32ch;
  color: var(--ink-soft);
  font-size: 1rem;
}

.speed-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1rem;
}

.speed-label {
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin-right: 0.15rem;
}

.speed-btn {
  padding: 0.4rem 0.75rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.55);
  font-size: 0.9rem;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.speed-btn:hover {
  border-color: var(--sea-deep);
  background: #fff;
}

.speed-btn.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

/* Modes */
.modes {
  display: flex;
  gap: 0.35rem;
  padding: 0 clamp(1.25rem, 5vw, 3rem);
  max-width: 1100px;
  margin: 0 auto 1.5rem;
  overflow-x: auto;
  animation: rise 0.8s var(--ease) 0.08s both;
}

.mode-btn {
  flex: 0 0 auto;
  padding: 0.65rem 1.1rem;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 1rem;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), transform 0.2s var(--ease);
}

.mode-btn:hover {
  transform: translateY(-1px);
}

.mode-btn.is-active {
  background: var(--ink);
  color: var(--paper);
}

/* Panels */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 clamp(1.25rem, 5vw, 3rem) 4rem;
}

.panel {
  display: none;
  animation: rise 0.55s var(--ease) both;
}

.panel.is-active {
  display: block;
}

.panel-intro h1 {
  margin: 0;
  font-weight: 700;
  font-size: clamp(1.35rem, 3.5vw, 1.75rem);
}

.panel-intro p {
  margin: 0.4rem 0 1.25rem;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

/* Chart */
.explain-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
  padding: clamp(1.5rem, 5vw, 2.5rem) 1rem;
  border: 1.5px solid var(--ink);
  border-radius: calc(var(--radius) + 4px);
  background:
    radial-gradient(ellipse 70% 55% at 50% 20%, rgba(232, 93, 58, 0.18), transparent 60%),
    linear-gradient(165deg, #1a2733 0%, #0f1820 55%, #162430 100%);
  color: #f2f6f9;
  overflow: visible;
  min-height: 280px;
}

.explain-glow {
  position: absolute;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(232, 93, 58, 0.55), transparent 70%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.08s linear, transform 0.08s linear;
}

.explain-stage.is-beeping .explain-glow {
  opacity: 1;
  transform: scale(1.25);
}

.explain-progress {
  margin: 0;
  position: relative;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  color: rgba(242, 246, 249, 0.65);
}

.explain-glyph {
  position: relative;
  width: min(260px, 68vw);
  aspect-ratio: 5 / 6;
  margin: 0.35rem 0 0.35rem;
  padding-top: 0.35rem;
}

.explain-glyph.is-swap {
  animation: letter-pop 0.4s var(--ease) both;
}

.explain-glyph .glyph-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.explain-glyph .glyph-letter {
  fill: rgba(242, 246, 249, 0.42);
  font-family: Arial, "Helvetica Neue", sans-serif;
  letter-spacing: -0.04em;
  user-select: none;
  pointer-events: none;
}

.explain-glyph .glyph-mark {
  fill: #f4f7fa;
  stroke: #f4f7fa;
  stroke-width: 11;
  opacity: 0.34;
  transition:
    opacity 0.15s linear,
    fill 0.08s linear,
    stroke 0.08s linear,
    filter 0.12s linear;
}

.explain-glyph .glyph-mark-dot {
  stroke: none;
}

.explain-glyph .glyph-mark-dash {
  stroke: none;
}

.explain-glyph .glyph-mark-arc {
  fill: none;
  stroke-dasharray: none;
  stroke-dashoffset: 0;
  transition:
    opacity 0.12s linear,
    stroke 0.08s linear,
    filter 0.12s linear;
}

.explain-glyph.is-playing .glyph-mark:not(.is-revealed) {
  opacity: 0.22;
}

.explain-glyph .glyph-mark.is-revealed {
  opacity: 1;
  animation: mark-pop 0.28s var(--ease) both;
}

.explain-glyph .glyph-mark.is-active {
  fill: var(--signal);
  stroke: var(--signal);
  filter: drop-shadow(0 0 12px rgba(232, 93, 58, 0.8));
}

.explain-glyph.is-complete .glyph-mark.is-revealed {
  fill: #f6c3b4;
  stroke: #f6c3b4;
}

.explain-glyph .glyph-start {
  opacity: 0.95;
}

.explain-glyph .glyph-start circle {
  fill: #f2f6f9;
}

.explain-glyph .glyph-start text {
  fill: #14202b;
  font-family: var(--font-body);
  pointer-events: none;
}

.explain-glyph .glyph-arrow path {
  stroke: #f2f6f9;
  stroke-width: 2.5;
  opacity: 0.85;
}

.explain-glyph .glyph-fallback {
  display: grid;
  place-items: center;
  height: 100%;
  font-weight: 700;
  font-size: clamp(4.5rem, 18vw, 7rem);
  color: #f2f6f9;
}

@keyframes mark-pop {
  from {
    opacity: 0.15;
  }
  to {
    opacity: 1;
  }
}

.explain-letter {
  margin: 0;
  position: relative;
  font-weight: 700;
  font-size: clamp(4.5rem, 18vw, 7rem);
  line-height: 1;
  letter-spacing: -0.03em;
  animation: letter-pop 0.35s var(--ease) both;
}

.explain-letter.is-swap {
  animation: letter-pop 0.35s var(--ease) both;
}

.explain-bars {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
  min-height: 30px;
}

.explain-bar {
  height: 20px;
  border-radius: 999px;
  background: rgba(242, 246, 249, 0.3);
  transform: scaleX(0.35);
  opacity: 0.6;
  transform-origin: left center;
  transition: background 0.08s linear, opacity 0.2s var(--ease), transform 0.25s var(--ease);
}

.explain-bar.dot {
  width: 18px;
}

.explain-bar.dash {
  width: 54px;
}

.explain-bar.is-revealed {
  opacity: 0.95;
  transform: scaleX(1);
  background: rgba(242, 246, 249, 0.55);
}

.explain-bar.is-active {
  background: var(--signal);
  opacity: 1;
  transform: scaleX(1);
  box-shadow: 0 0 18px rgba(232, 93, 58, 0.65);
}

.explain-code {
  margin: 0;
  position: relative;
  min-height: 1.4em;
  font-family: var(--font-mono);
  font-size: clamp(1.5rem, 5vw, 2.2rem);
  font-weight: 500;
  letter-spacing: 0.22em;
  color: #f6c3b4;
}

.explain-hint {
  margin: 0;
  position: relative;
  min-height: 1.3em;
  font-size: 0.95rem;
  color: rgba(242, 246, 249, 0.72);
  text-align: center;
}

.explain-controls {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  margin-top: 0.35rem;
}

.explain-stage .primary-btn {
  min-width: 5.5rem;
  padding: 0.65rem 1.1rem;
}

.explain-stage .secondary-btn {
  padding: 0.65rem 0.9rem;
  background: rgba(255, 255, 255, 0.08);
  color: #f2f6f9;
  border-color: rgba(242, 246, 249, 0.35);
}

.explain-stage .secondary-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border-color: rgba(242, 246, 249, 0.7);
}

.explain-stage .text-btn {
  color: #f6c3b4;
}

@keyframes letter-pop {
  from {
    opacity: 0;
    transform: scale(0.82) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.mnemonic-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.mnemonic-tip {
  margin: 0 0 1rem;
  padding: 0.75rem 0.9rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.65);
  font-size: 0.9rem;
  color: var(--ink-soft);
  line-height: 1.55;
}

.chart-filters {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.chip {
  padding: 0.4rem 0.85rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.45);
  font-size: 0.9rem;
  transition: border-color 0.2s, background 0.2s;
}

.chip.is-active {
  border-color: var(--ink);
  background: #fff;
}

.chart {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.55rem;
}

.char-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  padding: 0.85rem 0.75rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.55);
  text-align: left;
  transition: border-color 0.2s, transform 0.2s var(--ease), background 0.2s;
  animation: rise 0.5s var(--ease) both;
}

.char-card:hover,
.char-card:focus-visible {
  border-color: var(--sea-deep);
  background: #fff;
  transform: translateY(-2px);
  outline: none;
}

.char-card.is-playing {
  border-color: var(--signal);
  background: #fff7f4;
}

.char-card .letter {
  font-weight: 700;
  font-size: 1.5rem;
  line-height: 1.1;
}

.char-card .code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: var(--sea-deep);
  word-break: break-all;
}

.char-card .cyrillic {
  font-size: 0.75em;
  font-weight: 500;
  color: var(--ink-soft);
}

.char-card .mnemonic {
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--ink);
  word-break: break-word;
}

.char-card .mnemonic.ru {
  font-family: var(--font-body);
  color: var(--sea-deep);
}

/* Drill shared */
.drill {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: clamp(1.5rem, 5vw, 2.5rem) 1rem;
  border: 1.5px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(6px);
}

.signal-lamp {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #f7fafc, #cfdce6);
}

.lamp-core {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--sea);
  opacity: 0.35;
  transition: background 0.05s linear, opacity 0.05s linear, transform 0.05s linear;
}

.signal-lamp.is-on .lamp-core {
  background: var(--signal);
  opacity: 1;
  transform: scale(1.08);
}

.play-btn,
.primary-btn,
.secondary-btn,
.key-pad {
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  font-weight: 500;
}

.play-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem 1.25rem;
  background: #fff;
  transition: background 0.2s, transform 0.2s var(--ease);
}

.play-btn:hover {
  background: var(--paper-2);
  transform: translateY(-1px);
}

.play-icon {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 6px 0 6px 10px;
  border-color: transparent transparent transparent var(--ink);
}

.answer-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch;
  justify-content: center;
}

.answer-input {
  width: 4.5rem;
  text-align: center;
  font-weight: 700;
  font-size: 2rem;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  background: #fff;
  text-transform: uppercase;
  padding: 0.2rem;
}

.answer-input:focus {
  outline: 2px solid var(--sea);
  outline-offset: 2px;
}

.primary-btn {
  padding: 0 1.25rem;
  background: var(--ink);
  color: var(--paper);
  transition: background 0.2s, transform 0.2s var(--ease);
}

.primary-btn:hover {
  background: var(--sea-deep);
  transform: translateY(-1px);
}

.secondary-btn {
  padding: 0 1rem;
  background: #fff;
  color: var(--ink-soft);
  border-color: var(--line);
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.2s var(--ease);
}

.secondary-btn:hover {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--paper-2);
  transform: translateY(-1px);
}

.score-row .secondary-btn {
  padding: 0.45rem 0.85rem;
  font-size: 0.9rem;
}

.morse-display {
  margin: 0;
  font-family: var(--font-mono);
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 500;
  letter-spacing: 0.14em;
  color: var(--sea-deep);
  min-height: 1.2em;
}

.morse-display.sent {
  color: var(--ink);
  min-height: 1.4em;
}

.target-label {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.target-char {
  margin: 0;
  font-weight: 700;
  font-size: clamp(3rem, 12vw, 4.5rem);
  line-height: 1.1;
}

.target-morse {
  color: var(--ink-soft);
  font-size: 1.2rem;
}

.key-pad {
  width: min(100%, 280px);
  height: 120px;
  font-size: 1.2rem;
  letter-spacing: 0.08em;
  background: linear-gradient(180deg, #f8fbfd, #d5e0ea);
  user-select: none;
  touch-action: none;
  transition: background 0.05s, transform 0.05s;
}

.key-pad:active,
.key-pad.is-down {
  background: linear-gradient(180deg, #ffd8cc, #f0a58f);
  transform: scale(0.985);
}

.feedback {
  margin: 0;
  min-height: 1.4em;
  font-size: 0.95rem;
  text-align: center;
}

.feedback.is-ok {
  color: var(--ok);
}

.feedback.is-bad {
  color: var(--bad);
}

.feedback.is-unknown {
  color: var(--ink-soft);
}

.score-row,
.scope-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.score-row strong {
  color: var(--ink);
  font-weight: 500;
}

.countdown strong {
  font-family: var(--font-mono);
  font-size: 1.15em;
  font-weight: 500;
}

.text-btn {
  text-decoration: underline;
  text-underline-offset: 3px;
  color: var(--sea-deep);
  font-size: 0.85rem;
}

.scope-row label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.hint {
  margin: 0;
  max-width: 40ch;
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

/* Convert */
.convert-stage {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: clamp(1.5rem, 5vw, 2.5rem) clamp(1rem, 4vw, 1.75rem);
  border: 1.5px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(6px);
  animation: rise 0.55s var(--ease) both;
}

.convert-label {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.convert-input {
  width: 100%;
  resize: vertical;
  min-height: 5.5rem;
  padding: 0.9rem 1rem;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  background: #fff;
  font-family: var(--font-mono);
  font-size: clamp(1.15rem, 3.5vw, 1.45rem);
  font-weight: 500;
  letter-spacing: 0.06em;
  line-height: 1.45;
  text-transform: uppercase;
}

.convert-input:focus {
  outline: 2px solid var(--sea);
  outline-offset: 2px;
}

.convert-input::placeholder {
  color: rgba(58, 74, 88, 0.45);
  text-transform: none;
  letter-spacing: 0.02em;
  font-weight: 400;
}

.convert-note {
  margin: -0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.convert-output-block {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.35rem;
  padding: 1.15rem 1rem 1.35rem;
  border: 1.5px solid var(--ink);
  border-radius: calc(var(--radius) + 2px);
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(232, 93, 58, 0.12), transparent 55%),
    linear-gradient(165deg, #1a2733 0%, #0f1820 60%, #162430 100%);
  color: #f2f6f9;
  overflow: hidden;
}

.convert-output-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.convert-output-block .convert-label {
  color: rgba(242, 246, 249, 0.65);
}

.convert-live-char {
  min-height: 1.2em;
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: 0.04em;
  color: var(--signal);
}

.convert-lamp {
  align-self: center;
  border-color: rgba(242, 246, 249, 0.45);
  background: linear-gradient(160deg, #243442, #15202a);
}

.convert-lamp .lamp-core {
  background: rgba(242, 246, 249, 0.35);
}

.convert-output {
  margin: 0;
  min-height: 2.4em;
  font-family: var(--font-mono);
  font-size: clamp(1.25rem, 4vw, 1.85rem);
  font-weight: 500;
  letter-spacing: 0.1em;
  line-height: 1.55;
  color: #f6c3b4;
  word-break: break-word;
  white-space: pre-wrap;
  text-align: center;
  animation: convert-flash 0.35s var(--ease);
}

.convert-output.is-empty {
  color: rgba(242, 246, 249, 0.35);
  letter-spacing: 0.2em;
}

.convert-skipped {
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  color: rgba(242, 246, 249, 0.7);
}

.convert-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  justify-content: center;
  margin-top: 0.25rem;
}

.convert-actions .secondary-btn {
  padding: 0.7rem 1rem;
}

@keyframes convert-flash {
  from {
    opacity: 0.35;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.site-footer {
  padding: 0 clamp(1.25rem, 5vw, 3rem) 2.5rem;
  max-width: 1100px;
  margin: 0 auto;
  color: var(--ink-soft);
  font-size: 0.75rem;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 520px) {
  .chart {
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  }

  .char-card {
    padding: 0.7rem 0.55rem;
  }

  .char-card .letter {
    font-size: 1.3rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
