:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #14141f;
  --bg-tertiary: #1e1e2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent: #00d4ff;
  --accent-secondary: #00ff88;
  --danger: #ff4466;
  --warn: #ffb454;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --radius-md: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

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

html, body {
  width: 600px; height: 600px; overflow: hidden;
  background: #000;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#app { width: 100%; height: 100%; position: relative; }

.screen {
  width: 100%; height: 100%; position: absolute; top: 0; left: 0;
  display: flex; flex-direction: column;
}
.screen.hidden { display: none; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); }

button {
  font: inherit; color: inherit; background: none;
  -webkit-appearance: none; appearance: none;
}

.focusable {
  transition: border-color 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  border: 2px solid transparent;
  cursor: pointer; outline: none;
}
.focusable:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
}

/* ---------- HOME ---------- */
.app-header {
  padding: 30px 28px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.app-title {
  font-size: 40px; font-weight: 700; letter-spacing: -0.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-secondary));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.app-sub { font-size: 15px; color: var(--text-secondary); letter-spacing: 2px; text-transform: uppercase; }

.menu {
  flex: 1; display: flex; flex-direction: column; gap: 12px;
  padding: 10px 20px;
}
.menu-item {
  display: flex; align-items: center; gap: 16px;
  min-height: 92px; padding: 0 18px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  text-align: left;
}
.menu-item:focus { background: var(--bg-tertiary); }
.menu-badge {
  flex: 0 0 54px; height: 54px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-tertiary);
  border-radius: 10px;
  font-family: var(--mono); font-size: 20px; font-weight: 600;
  color: var(--accent); letter-spacing: 1px;
}
.menu-item:focus .menu-badge { background: rgba(0,212,255,0.12); }
.menu-text { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.menu-label { font-size: 22px; font-weight: 600; }
.menu-desc { font-size: 14px; color: var(--text-secondary); }
.menu-chev { font-size: 30px; color: var(--text-muted); }

.hint-bar {
  padding: 14px; text-align: center;
  font-size: 13px; color: var(--text-muted);
  border-top: 1px solid var(--bg-tertiary);
}

/* ---------- SHARED BARS ---------- */
.ed-header, .bar-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--bg-tertiary);
}
.ed-icon-btn {
  flex: 0 0 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; line-height: 1;
  background: var(--bg-tertiary); border-radius: 10px;
  color: var(--text-secondary);
}
.mode-toggle {
  flex: 1; height: 46px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--bg-tertiary); border-radius: 10px;
  font-size: 17px; font-weight: 700; letter-spacing: 2px;
  color: var(--accent);
}
.mode-switch { color: var(--text-secondary); font-size: 19px; }
.char-count { flex: 0 0 auto; font-family: var(--mono); font-size: 13px; color: var(--text-muted); padding-right: 4px; }
.char-max { color: var(--text-muted); opacity: 0.6; }

.bar-back, .bar-action {
  height: 44px; padding: 0 14px;
  display: flex; align-items: center;
  background: var(--bg-tertiary); border-radius: 10px;
  font-size: 16px; color: var(--text-secondary);
}
.bar-title {
  flex: 1; text-align: center;
  font-size: 16px; font-weight: 700; letter-spacing: 2px;
  color: var(--text-secondary);
}
.bar-spacer { flex: 0 0 60px; }

/* ---------- IO AREA ---------- */
.io-label {
  font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 6px;
}
.io-area { padding: 12px 14px 6px; }
.io-box {
  min-height: 58px; max-height: 86px; overflow-y: auto;
  padding: 12px 14px;
  background: var(--bg-secondary); border-radius: 10px;
  font-family: var(--mono); font-size: 18px; line-height: 1.4;
  color: var(--text-primary);
  word-break: break-all; white-space: pre-wrap;
}
.input-box .placeholder { color: var(--text-muted); }
.caret {
  display: inline-block; width: 2px; height: 20px;
  background: var(--accent); vertical-align: text-bottom;
  margin-left: 1px; animation: blink 1.1s steps(2, start) infinite;
}
@keyframes blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

.io-preview {
  display: flex; align-items: baseline; gap: 8px;
  margin-top: 8px; padding: 0 4px;
  min-height: 24px;
}
.io-arrow { color: var(--accent-secondary); font-size: 16px; flex: 0 0 auto; }
.preview-text {
  font-family: var(--mono); font-size: 15px; color: var(--accent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0;
}
#output-preview.muted { color: var(--text-muted); }

/* ---------- KEYBOARD ---------- */
.keyboard {
  flex: 1; display: flex; flex-direction: column; justify-content: flex-end;
  gap: 7px; padding: 8px 8px 12px;
}
.kb-row { display: flex; gap: 6px; justify-content: center; }
.key {
  flex: 1 1 0; min-width: 0; min-height: 58px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-tertiary); border-radius: 9px;
  font-size: 22px; color: var(--text-primary);
  font-family: var(--mono);
}
.key:focus { background: var(--bg-secondary); }
.key.special {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 16px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.key.special:focus { background: var(--bg-tertiary); }
.key.wide-space { flex: 4 1 0; letter-spacing: 1px; }
.key.done { color: var(--accent-secondary); font-weight: 700; font-size: 22px; }

/* morse input pad (decode mode) */
.key.morse-tap {
  min-height: 104px; font-size: 56px; line-height: 1;
  color: var(--accent); font-weight: 700;
}
.key.morse-tap:focus { background: var(--bg-secondary); }

/* ---------- RESULT ---------- */
.res-body { flex: 1; display: flex; flex-direction: column; padding: 14px 16px 8px; min-height: 0; }
.res-input {
  max-height: 84px; overflow-y: auto;
  padding: 10px 12px; margin-bottom: 14px;
  background: var(--bg-secondary); border-radius: 10px;
  font-family: var(--mono); font-size: 15px; color: var(--text-secondary);
  word-break: break-all; white-space: pre-wrap;
}
.res-output {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 14px; border-radius: 10px;
  background: var(--bg-secondary);
  font-family: var(--mono); font-size: 20px; line-height: 1.5;
  color: var(--accent);
  word-break: break-all; white-space: pre-wrap;
  letter-spacing: 1px;
}
.res-output.is-text { color: var(--text-primary); letter-spacing: 0; }
.res-actions { display: flex; gap: 10px; padding: 10px 14px 16px; }
.res-btn {
  flex: 1; min-height: 64px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-secondary); border-radius: 10px;
  font-size: 16px; color: var(--text-primary);
}
.res-btn:focus { background: var(--bg-tertiary); }
.res-btn.flash-btn { color: var(--accent); font-weight: 600; }
.res-btn.flash-btn:focus { background: rgba(0,212,255,0.12); }

/* ---------- FLASH ---------- */
.flash-meta { padding: 12px 16px 6px; }
.flash-label {
  font-size: 18px; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-height: 24px;
}
.flash-code {
  margin-top: 8px; font-size: 17px; line-height: 1.5;
  color: var(--text-secondary);
  max-height: 56px; overflow: hidden;
  word-break: break-word;
}
.fm-letter { margin-right: 12px; white-space: nowrap; }
.fm-slash { color: var(--text-muted); margin: 0 6px; }
.fm-sym { transition: color 0.04s linear; }
.fm-sym.lit { color: var(--accent-secondary); text-shadow: 0 0 12px var(--accent-secondary); }

.flash-stage {
  flex: 1; margin: 8px 16px;
  border-radius: 18px;
  background: var(--bg-primary);
  display: flex; align-items: center; justify-content: center;
  transition: background-color 0s;
}
.flash-stage.on {
  background: #ffffff;
  box-shadow: 0 0 80px rgba(255,255,255,0.55);
}
.flash-glyph {
  font-family: var(--mono); font-size: 120px; line-height: 1;
  color: transparent;
}
.flash-stage.on .flash-glyph { color: #0a0a0f; }

/* ---------- REFERENCE ---------- */
.ref-body { flex: 1; overflow-y: auto; padding: 14px; }
.ref-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ref-cell {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 46px; padding: 8px 12px;
  background: var(--bg-secondary); border-radius: 9px;
}
.ref-char { font-size: 18px; font-weight: 700; color: var(--text-primary); }
.ref-code { font-family: var(--mono); font-size: 15px; color: var(--accent); letter-spacing: 1px; }

/* ---------- ABOUT ---------- */
.about-body { flex: 1; overflow-y: auto; padding: 18px 20px; }
.about-body h2 { font-size: 22px; margin-bottom: 10px; }
.about-body h3 { font-size: 16px; color: var(--accent); margin: 18px 0 8px; letter-spacing: 1px; }
.about-body p { font-size: 15px; color: var(--text-secondary); line-height: 1.5; margin-bottom: 10px; }
.about-body code { font-family: var(--mono); color: var(--accent-secondary); background: var(--bg-tertiary); padding: 1px 5px; border-radius: 4px; }
.about-row { display: flex; gap: 12px; align-items: baseline; padding: 5px 0; font-size: 15px; color: var(--text-secondary); }
.about-key {
  flex: 0 0 78px; font-weight: 600; color: var(--text-primary);
  font-family: var(--mono); font-size: 14px;
}
.about-foot { margin-top: 16px; font-size: 13px; color: var(--text-muted); }

/* ---------- TOAST ---------- */
.toast {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(8px);
  max-width: 80%;
  padding: 12px 22px;
  background: var(--bg-tertiary);
  border: 1px solid var(--accent);
  border-radius: 24px;
  font-size: 15px; color: var(--text-primary);
  box-shadow: 0 6px 24px rgba(0,0,0,0.6);
  opacity: 0; transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
