:root {
  /* Dark theme values, used as the default/fallback regardless of
     OS preference until overridden below. */
  --bg: #0d0d14;
  --bg-raised: #16161f;
  --text: #f5f3ff;
  --text-dim: #9a96b3;
  --hit: #1c9956;
  --partial: #ffb23d;
  --miss: #3a3a4a;
  --unknown: #5a5a6e;
  --border: #2a2a38;
  --focus: #4d8fe0;

  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* OS prefers light, and the person hasn't manually overridden it
   (no data-theme attribute set yet). */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
  --bg: #f8fafc;
  --bg-raised: #ffffff;
  --text: #0f172a;
  --text-dim: #64748b;
  --hit: #16a34a;
  --partial: #d97706;
  --miss: #cbd5e1;
  --unknown: #94a3b8;
  --border: #e2e8f0;
  --focus: #2563eb;
  }
}

/* Manual override — wins regardless of OS preference once the person
   has explicitly chosen a theme via the toggle (see js/theme.js). */
:root[data-theme='dark'] {
  --bg: #0d0d14;
  --bg-raised: #16161f;
  --text: #f5f3ff;
  --text-dim: #9a96b3;
  --hit: #1c9956;
  --partial: #ffb23d;
  --miss: #3a3a4a;
  --unknown: #5a5a6e;
  --border: #2a2a38;
  --focus: #4d8fe0;
}

:root[data-theme='light'] {
  --bg: #f8fafc;
  --bg-raised: #ffffff;
  --text: #0f172a;
  --text-dim: #64748b;
  --hit: #16a34a;
  --partial: #d97706;
  --miss: #cbd5e1;
  --unknown: #94a3b8;
  --border: #e2e8f0;
  --focus: #2563eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.stage {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 64px;
  min-height: 100vh;
}

/* ---------------- Topbar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
}

.brand-mark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.icon-button:hover {
  border-color: var(--focus);
}

/* ---------------- Game shell ---------------- */

.game {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.prompt {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 500;
  margin: 0;
  color: var(--text);
}

/* ---------------- Guess input ---------------- */

.guess-box {
  position: relative;
}

#guess-input {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease;
}

#guess-input:focus {
  border-color: var(--focus);
}

#guess-input:disabled {
  opacity: 0.5;
}

.suggestions {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  z-index: 10;
  max-height: 280px;
  overflow-y: auto;
}

.suggestions.visible {
  display: block;
}

.suggestion-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  padding: 12px 16px;
  cursor: pointer;
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover,
.suggestion-item:focus {
  background: rgba(255, 61, 110, 0.12);
}

/* ---------------- End banner ---------------- */

.end-banner {
  display: none;
}

.end-banner.visible {
  display: block;
}

.end-card {
  background: var(--bg-raised);
  border: 1px solid var(--focus);
  border-radius: 10px;
  padding: 16px;
}

.end-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 4px;
}


.end-sub {
  font-size: 14px;
  color: var(--text-dim);
  margin: 0 0 12px;
}

.countdown-display {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}
 
.share-button {
  background: var(--hit);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 24px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
  display: block;
  width: fit-content;
  margin: 0 auto;
}
 
.share-button:hover:not(:disabled) {
  opacity: 0.9;
}
 
.share-button:disabled {
  cursor: default;
  opacity: 0.8;
}

/* ---------------- Board / grid ---------------- */

.board {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.empty-state,
.error-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

.row {
  display: grid;
  grid-template-columns: 1.5fr 1.7fr 1.5fr 2.3fr 1.3fr;
  gap: 6px;
  perspective: 600px;
}

.row--header {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  text-transform: uppercase;
  padding: 0 2px 2px;
}

.row--newest {
  animation: slideIn 0.25s ease-out;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .row--newest { animation: none; }
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 12px 6px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  min-height: 48px;
}

.cell--header {
  background: none;
  min-height: auto;
  padding: 0 6px;
  justify-content: flex-start;
}

/* ---------------- Card flip reveal ----------------*/
.cell--flip {
  animation: cardFlip 0.5s ease-in-out both;
  animation-delay: var(--flip-delay, 0s);
  border-width: 1px;
  border-style: dashed;
}

@keyframes cardFlip {
  0% {
    transform: rotateY(0deg);
    background: var(--bg-raised);
    color: var(--text-dim);
    border-color: transparent;
  }
  49% {
    background: var(--bg-raised);
    color: var(--text-dim);
    border-color: transparent;
  }
  50% {
    transform: rotateY(90deg);
    background: var(--flip-reveal-bg, var(--bg-raised));
    color: var(--flip-reveal-color, var(--text));
    border-color: var(--flip-reveal-border, transparent);
  }
  100% {
    transform: rotateY(0deg);
    background: var(--flip-reveal-bg, var(--bg-raised));
    color: var(--flip-reveal-color, var(--text));
    border-color: var(--flip-reveal-border, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  /* Backstop only — ui.js checks this same preference before ever
     adding the cell--flip class, so this rule shouldn't normally be
     load-bearing. Kept in case cell--flip is ever applied some other
     way in the future. */
  .cell--flip {
    animation: none;
  }
}

.cell--name {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  background: var(--bg-raised);
  text-align: left;
  font-weight: 600;
}

.liver-name-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0; /* allows text truncation/wrapping inside a constrained grid column */
}

.liver-thumb {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
}

.liver-thumb--suggestion {
  width: 28px;
  height: 28px;
}

.liver-name {
  font-size: 14px;
}

.liver-name-jp {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 400;
}

.cell--hit {
  background: var(--hit);
  color: #fff;
}

.cell--partial {
  background: var(--partial);
  color: #1a1300;
}

.cell--miss {
  background: var(--miss);
  color: var(--text);
}

.cell--unknown {
  background: transparent;
  border: 1px dashed var(--unknown);
  color: var(--text-dim);
}

.cell--swatches {
  gap: 4px;
}

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.arrow {
  margin-left: 4px;
  font-weight: 700;
}

/* ---------------- Legend ---------------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.legend-swatch--hit { background: var(--hit); }
.legend-swatch--partial { background: var(--partial); }
.legend-swatch--miss { background: var(--miss); }
.legend-swatch--unknown { background: transparent; border: 1px dashed var(--unknown); }

/* ---------------- Site footer ---------------- */

.site-footer {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.footer-feedback-link {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  color: var(--focus);
  text-decoration: none;
  margin-bottom: 10px;
}

.footer-feedback-link:hover {
  text-decoration: underline;
}

.footer-disclaimer {
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-dim);
  max-width: 480px;
  margin: 0 auto;
}

.footer-text {
  font-size: 11px;
  line-height: 1.5;
  max-width: 480px;
  margin: 0 auto;
}

/* ---------------- Overlay Modal ---------------- */

.overlay-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.overlay-overlay.visible {
  display: flex;
}

.overlay-dialog {
  position: relative;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 28px 24px 24px;
}

.overlay-dialog:focus {
  outline: none;
}

.overlay-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  border-radius: 999px;
}

.overlay-close:hover {
  background: var(--bg);
  color: var(--text);
}

.overlay-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 12px;
  padding-right: 24px;
}

.overlay-text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  margin: 0 0 16px;
}

.overlay-link {
  font-size: 14px;
  line-height: 1.5;
  color: var(--focus);
  margin: 0 0 16px;
  text-decoration: none;
}

.overlay-link:hover{
  text-decoration: underline;
}

.overlay-legend {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.overlay-legend li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
}

.overlay-legend .legend-swatch {
  margin-top: 3px; 
  flex-shrink: 0;
}

.overlay-start {
  width: 100%;
  background: var(--hit);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.overlay-start:hover {
  opacity: 0.9;
}

/* ---------------- Responsive ---------------- */

@media (max-width: 480px) {
  .cell {
    font-size: 11px;
    padding: 8px 3px;
  }
  .liver-name {
    display: none;
  }
  .has-image .liver-name-block {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .has-image {
    justify-content: center;
    position: relative;
  }
}

/* Keyboard focus visibility */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
