:root {
  --bg: #fdf6e3;
  --card: #ffffff;
  --ink: #2b2d42;
  --muted: #6c757d;
  --accent: #ff7f50;
  --accent-dark: #e8613a;
  --good: #2ecc71;
  --bad: #e74c3c;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; }

/* Author `display` rules (e.g. .result) would otherwise override the hidden attribute */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  padding: 0 16px 32px;
}

header {
  text-align: center;
  padding-top: 24px;
}

h1 {
  margin: 0 0 16px;
  font-size: 2.2rem;
  letter-spacing: 0.05em;
}

.tabs {
  display: inline-flex;
  background: #eee4cc;
  border-radius: 999px;
  padding: 4px;
}

.tab {
  border: none;
  background: transparent;
  padding: 10px 24px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}

.tab.active {
  background: var(--accent);
  color: #fff;
}

main {
  max-width: 560px;
  margin: 32px auto 0;
  text-align: center;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.card {
  flex: 1;
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 32px 16px;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.card.slide-left { animation: slideLeft 0.25s ease; }
.card.slide-right { animation: slideRight 0.25s ease; }

@keyframes slideLeft {
  from { transform: translateX(40px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes slideRight {
  from { transform: translateX(-40px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.char {
  font-size: 6rem;
  font-weight: 800;
  line-height: 1;
}

.char.flash { animation: pop 0.4s ease; }

@keyframes pop {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

.morse {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 24px;
  flex-wrap: wrap;
}

.morse .dot,
.morse .dash {
  display: inline-block;
  height: 18px;
  background: var(--ink);
  border-radius: 9px;
}
.morse .dot { width: 18px; }
.morse .dash { width: 54px; }
.morse .on { background: var(--accent); }

.morse-text {
  font-family: Consolas, monospace;
  font-size: 1.3rem;
  color: var(--muted);
  letter-spacing: 0.2em;
}

.nav-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}
.nav-btn:hover { background: var(--accent-dark); }

.progress {
  margin-top: 16px;
  font-weight: 600;
  color: var(--muted);
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

kbd {
  background: #eee;
  border-radius: 4px;
  padding: 1px 6px;
  border: 1px solid #ccc;
}

button.primary,
button.secondary {
  border: none;
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); }
button.secondary { background: #eee4cc; color: var(--ink); }
button.secondary:hover { background: #e2d6b8; }

.score {
  font-weight: 700;
  margin-bottom: 16px;
}

.keypad {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin: 24px 0 16px;
}

.key {
  width: 120px;
  height: 90px;
  border-radius: 20px;
  border: none;
  background: var(--ink);
  color: #fff;
  font-size: 2.2rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.08s;
}
.key:active, .key.pressed { transform: scale(0.94); background: var(--accent); }

.actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.result {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

.result-card {
  width: min(380px, 100%);
  background: var(--card);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.result-img svg {
  width: 180px;
  height: 180px;
  animation: bounce 0.6s ease;
}

.result-msg {
  font-size: 1.6rem;
  font-weight: 800;
}
.result.good .result-msg { color: var(--good); }
.result.bad .result-msg { color: var(--bad); }

.result-detail {
  color: var(--muted);
  font-family: Consolas, monospace;
  font-size: 1.05rem;
  max-width: 320px;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes bounce {
  0% { transform: scale(0.3) rotate(-15deg); }
  60% { transform: scale(1.1) rotate(5deg); }
  100% { transform: scale(1) rotate(0); }
}

@media (max-width: 420px) {
  .char { font-size: 4.5rem; }
  .key { width: 100px; height: 80px; }
  .nav-btn { width: 44px; height: 44px; }
}
