:root {
  /* Light theme palette (default) */
  --bg: #FAFAF7;
  --bg-elev: #FFFFFF;
  --bg-soft: #F1F1E8;
  --border: #ECECE0;
  --border-strong: #D4D4C2;
  --text: #1B1F4D;
  --text-muted: rgba(27, 31, 77, 0.65);
  --primary: #1B1F4D;
  --primary-fg: #FFFFFF;
  --accent: #FF6B5C;
  --pill-cold-bg: #C7E5FF; --pill-cold-fg: #114B7E;
  --pill-warm-bg: #FFE3B5; --pill-warm-fg: #7A4A00;
  --pill-hot-bg:  #FFD3CC; --pill-hot-fg:  #8B1F12;
  --pill-correct-bg: #CFEFCB; --pill-correct-fg: #1F5C16;
  --modal-overlay: rgba(0, 0, 0, 0.55);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  --transition: 200ms cubic-bezier(0.2, 0.7, 0.3, 1);
}

[data-theme="dark"] {
  --bg: #14163A;
  --bg-elev: #1E2150;
  --bg-soft: #1E2150;
  --border: #2A2E5C;
  --border-strong: #2A2E5C;
  --text: #F4F4FA;
  --text-muted: rgba(244, 244, 250, 0.65);
  --primary: #FF6B5C;
  --primary-fg: #FFFFFF;
  --accent: #3FBFC0;
  --pill-cold-bg: #1B3A60; --pill-cold-fg: #B8DBFF;
  --pill-warm-bg: #5C3F0E; --pill-warm-fg: #FFD89B;
  --pill-hot-bg:  #5E1D14; --pill-hot-fg:  #FFC5BC;
  --pill-correct-bg: #1F5C16; --pill-correct-fg: #CFEFCB;
  --modal-overlay: rgba(0, 0, 0, 0.7);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  transition: background var(--transition), color var(--transition);
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.logo-link { display: inline-block; line-height: 0; }
.logo-img { height: clamp(64px, 14vw, 96px); width: auto; max-width: 75vw; }
[data-theme="dark"] .logo-img {
  background: #FAFAF7;
  padding: 4px 8px;
  border-radius: 8px;
}
.header-controls { display: flex; gap: 8px; }
.icon-btn {
  width: 50px; height: 50px;
  border-radius: 12px;
  border: none;
  background: var(--bg-soft);
  color: var(--text);
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
}
.header-controls { gap: 10px; }
.icon-btn:hover { background: var(--border); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Game */
.meta { font-size: 13px; color: var(--text-muted); margin: 0 0 10px; }
.riddle-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 20px;
  border-radius: 12px;
  margin-bottom: 18px;
  font-style: italic;
  font-size: 17px;
  line-height: 1.5;
}

.attempts { list-style: none; padding: 0; margin: 0 0 18px; display: flex; flex-direction: column; gap: 8px; }
.attempts li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-soft);
  padding: 13px 16px;
  border-radius: 10px;
  font-size: 16px;
  animation: row-in 280ms cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 20px;
  padding: 4px 8px;
  border-radius: 999px;
  animation: pill-bounce 360ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.pill .pill-text {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  opacity: 0.75;
  padding-right: 4px;
}
.pill-cold { background: var(--pill-cold-bg); color: var(--pill-cold-fg); }
.pill-warm { background: var(--pill-warm-bg); color: var(--pill-warm-fg); }
.pill-hot  { background: var(--pill-hot-bg);  color: var(--pill-hot-fg); }
.pill-correct { background: var(--pill-correct-bg); color: var(--pill-correct-fg); }

/* Hint area */
.hint {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 4px;
  margin-bottom: 14px;
  min-height: 32px;
}
.hint .letter {
  display: inline-block;
  margin: 0 2px;
  width: 0.9em;
  text-align: center;
}
.hint .letter.revealed {
  animation: letter-flip 400ms ease-out both;
  color: var(--accent);
}
.hint .word-gap { display: inline-block; width: 1.2em; }

/* Form */
form { display: flex; gap: 8px; }
form[hidden] { display: none; }
input[type="text"] {
  flex: 1;
  padding: 14px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 17px;
  font-family: inherit;
}
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}
button {
  padding: 14px 22px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: var(--primary-fg);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: opacity var(--transition);
}
button:hover { opacity: 0.9; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Footer */
.footer {
  margin-top: auto;
  padding-top: 24px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  align-items: center;
}
.footer a { color: inherit; }
.footer-sep { opacity: 0.5; }

/* End screen (rendered inside modal) */
.end-modal { position: relative; max-width: 420px; }
.modal-close-x {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.modal-close-x:hover { background: var(--bg-soft); color: var(--text); }
.end-headline { margin: 0 0 8px; font-size: 18px; padding-right: 32px; }
.end-sub { margin: 0 0 16px; color: var(--text-muted); font-size: 14px; }
.streak-line {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  padding: 10px 12px;
  background: var(--bg-soft);
  border-radius: 8px;
  font-size: 13px;
}
.streak-line span { font-weight: 700; }

.distribution {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.dist-title { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.dist-row {
  display: grid;
  grid-template-columns: 16px 1fr 36px;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin: 4px 0;
}
.dist-bar-wrap { background: var(--bg-soft); border-radius: 4px; overflow: hidden; height: 14px; }
.dist-bar {
  background: var(--primary);
  height: 100%;
  border-radius: 4px;
  transition: width 600ms ease-out;
}
.dist-row.you .dist-bar { background: var(--accent); }
.dist-row.you { font-weight: 700; }

.next-riddle {
  margin-top: 16px;
  padding: 10px 12px;
  background: var(--bg-soft);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.share-row { margin-top: 16px; display: flex; gap: 8px; flex-wrap: wrap; }
.share-row button { flex: 1; min-width: 120px; padding: 10px 16px; font-size: 14px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--modal-overlay);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  z-index: 100;
  animation: overlay-in 240ms ease-out both;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 12px;
  padding: 22px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
  animation: modal-in 320ms cubic-bezier(0.2, 0.7, 0.3, 1) both;
}
.modal h2 { margin: 0 0 10px; font-size: 23px; }
.modal-lead { margin: 0 0 16px; color: var(--text-muted); font-size: 15px; }
.modal ol { padding-left: 20px; margin: 0 0 18px; font-size: 16px; line-height: 1.6; }
.modal-legend {
  display: flex; gap: 16px; justify-content: center;
  background: var(--bg-soft); padding: 14px;
  border-radius: 10px; margin-bottom: 18px;
}
.legend-item { text-align: center; font-size: 13px; }
.legend-emoji { display: block; font-size: 32px; margin-bottom: 6px; }
.primary-btn {
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: var(--primary-fg);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}

/* Confetti canvas */
#confetti-canvas {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1000;
}

/* Animations */
@keyframes row-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pill-bounce {
  0%   { opacity: 0; transform: scale(0.6); }
  60%  { opacity: 1; transform: scale(1.08); }
  100% { transform: scale(1); }
}
@keyframes letter-flip {
  0%   { transform: rotateY(90deg); opacity: 0; }
  100% { transform: rotateY(0deg); opacity: 1; }
}
@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(-12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0ms !important;
  }
}
