:root {
  --bg-deep: #0a0e27;
  --bg-mid: #131a3a;
  --panel-bg: rgba(18, 26, 58, 0.85);
  --panel-border: #4a9eff;
  --panel-border-dim: #2c5a8c;
  --text-main: #e8ecf7;
  --text-dim: #8b96b8;
  --gold: #e8c547;
  --correct: #00e5a0;
  --partial: #e8c547;
  --wrong: #b23a3a;
  --danger: #ff6b6b;
  --radius: 6px;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-display: "Cinzel", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at top, var(--bg-mid) 0%, var(--bg-deep) 70%);
  color: var(--text-main);
  font-family: var(--font-body);
  padding: 24px 16px 60px;
}

/* ---------- Header ---------- */

.site-header {
  text-align: center;
  margin-bottom: 28px;
}

.ff7-logo {
  display: block;
  width: min(340px, 72vw);
  height: auto;
  margin: 0 auto;
  filter: drop-shadow(0 0 20px rgba(74, 158, 255, 0.3));
}

.title {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.38em;
  /* tighten optically against the logo's baseline, compensating for the
     extra letter-spacing pushing the last glyph's edge out */
  padding-left: 0.38em;
  font-size: clamp(1.1rem, 3.4vw, 1.5rem);
  margin: -6px 0 0;
  color: var(--gold);
  text-shadow: 0 0 14px rgba(232, 197, 71, 0.4);
}

.subtitle {
  color: var(--text-dim);
  margin: 10px 0 0;
  font-size: 0.9rem;
}

/* ---------- Layout ---------- */

.game {
  max-width: 640px;
  margin: 0 auto;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.status-bar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- Auth controls ---------- */

.account-menu { position: relative; }

.account-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 6px;
}

.auth-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.auth-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-border-dim);
  color: var(--text-main);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.auth-name {
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: linear-gradient(180deg, #16234a 0%, #0e1730 100%);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  z-index: 40;
}
.account-dropdown.hidden { display: none; }

.account-dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--panel-border-dim);
  color: var(--text-main);
  font-size: 0.85rem;
  cursor: pointer;
}
.account-dropdown-item:last-child { border-bottom: none; }
.account-dropdown-item:hover { background: rgba(74, 158, 255, 0.12); }
.account-dropdown-danger { color: var(--danger); }
.account-dropdown-danger:hover { background: rgba(178, 58, 58, 0.15); }

.signin-body {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}
.signin-blurb {
  margin: 0 0 4px;
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
}
.btn-signin {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--text-main);
  color: #1a1a1a;
  border-color: var(--text-main);
  font-weight: 600;
}
.btn-signin:hover { filter: brightness(0.95); }
.btn-signin-apple {
  background: #0a0a0a;
  color: #fff;
  border-color: #0a0a0a;
}
.btn-signin-apple:hover { filter: brightness(1.3); }

.icon-btn {
  background: transparent;
  border: 1px solid var(--panel-border-dim);
  color: var(--text-main);
  border-radius: var(--radius);
  padding: 5px 12px;
  cursor: pointer;
  font-size: 0.85rem;
}
.icon-btn:hover { border-color: var(--panel-border); }

/* ---------- Search / autocomplete ---------- */

.search-wrap {
  position: relative;
  margin-bottom: 18px;
}

.materia-dot {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #7fffd4, #00a884 70%);
  box-shadow: 0 0 8px rgba(0, 229, 160, 0.6);
  pointer-events: none;
}

#guessInput {
  width: 100%;
  padding: 12px 14px 12px 34px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border-dim);
  border-radius: var(--radius);
  color: var(--text-main);
  font-size: 1rem;
  outline: none;
}
#guessInput:focus {
  border-color: var(--panel-border);
  box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.15);
}
#guessInput:disabled {
  opacity: 0.6;
  cursor: wait;
}

.autocomplete-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 4px;
  position: absolute;
  z-index: 20;
  width: 100%;
  max-height: 280px;
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border-dim);
  border-radius: var(--radius);
  backdrop-filter: blur(4px);
}
.autocomplete-list.hidden { display: none; }

.autocomplete-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.92rem;
}
.autocomplete-item:hover,
.autocomplete-item.active {
  background: rgba(74, 158, 255, 0.15);
}
.autocomplete-item img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex-shrink: 0;
}
.autocomplete-item .ac-cat {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.autocomplete-empty {
  padding: 10px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* ---------- Column labels (desktop only) ---------- */

.column-labels {
  display: none;
  grid-template-columns: 1.9fr 0.9fr 0.55fr 0.85fr 0.85fr 1.05fr 1.05fr 1.25fr 1.05fr;
  gap: 6px;
  padding: 0 2px;
  margin-bottom: 6px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}
@media (min-width: 700px) {
  .column-labels[data-active] { display: grid; }
}

/* ---------- Guess rows / tiles ---------- */

.guesses-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.guess-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border-dim);
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.guess-row:hover,
.guess-row:focus-visible {
  border-color: var(--panel-border);
}

@media (min-width: 700px) {
  .guess-row {
    grid-template-columns: 1.9fr 0.9fr 0.55fr 0.85fr 0.85fr 1.05fr 1.05fr 1.25fr 1.05fr;
  }
}

.tile {
  --tile-bg: var(--wrong);
  background: var(--tile-bg);
  border-radius: 4px;
  padding: 8px 8px;
  min-height: 46px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.8rem;
  line-height: 1.2;
  color: #fff;
  animation: flip-in 0.4s ease both;
}

.tile.correct { --tile-bg: var(--correct); color: #04231a; }
.tile.partial { --tile-bg: var(--partial); color: #2b2205; }
.tile.wrong   { --tile-bg: var(--wrong); }

.tile .tile-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  opacity: 0.75;
  margin-bottom: 2px;
}
.tile .tile-value { font-weight: 600; word-break: break-word; }
.tile .arrow { font-size: 0.85rem; margin-left: 3px; }

/* Array-attribute tiles show a short preview, not the full list, to keep row
   height predictable — click the row for the full breakdown. */
.tile .tile-value.tile-value-preview {
  font-size: 0.76rem;
  line-height: 1.25;
}

.tile-monster {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--panel-border-dim);
  min-width: 0; /* allow flex children to actually shrink instead of forcing wrap */
}
.tile-monster img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  flex-shrink: 0;
}
.tile-monster .tile-value {
  font-size: 0.85rem;
  text-align: left;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@keyframes flip-in {
  from { transform: rotateX(90deg); opacity: 0; }
  to   { transform: rotateX(0deg); opacity: 1; }
}

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

/* stagger tile reveal within a row */
.guess-row .tile:nth-child(1) { animation-delay: 0s; }
.guess-row .tile:nth-child(2) { animation-delay: 0.05s; }
.guess-row .tile:nth-child(3) { animation-delay: 0.10s; }
.guess-row .tile:nth-child(4) { animation-delay: 0.15s; }
.guess-row .tile:nth-child(5) { animation-delay: 0.20s; }
.guess-row .tile:nth-child(6) { animation-delay: 0.25s; }
.guess-row .tile:nth-child(7) { animation-delay: 0.30s; }
.guess-row .tile:nth-child(8) { animation-delay: 0.35s; }
.guess-row .tile:nth-child(9) { animation-delay: 0.40s; }

/* ---------- Modals ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 20, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal-overlay.hidden { display: none; }

.ff-window {
  background: linear-gradient(180deg, #16234a 0%, #0e1730 100%);
  border: 2px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: 0 0 0 1px rgba(74,158,255,0.25), 0 12px 40px rgba(0,0,0,0.6);
  width: 100%;
  max-width: 380px;
  overflow: hidden;
}

.modal-header {
  background: rgba(74, 158, 255, 0.12);
  border-bottom: 1px solid var(--panel-border-dim);
  padding: 10px 16px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.modal-body {
  padding: 18px 16px 6px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.end-body { flex-direction: column; text-align: center; }

#endMessage { margin: 4px 0 0; line-height: 1.4; }
.end-sub { color: var(--text-dim); font-size: 0.85rem; }

.confirm-portrait {
  width: 72px;
  height: 72px;
  object-fit: contain;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--panel-border-dim);
  border-radius: 6px;
  flex-shrink: 0;
}

.end-portrait {
  width: 148px;
  height: 148px;
}

.zoomable {
  cursor: zoom-in;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.zoomable:hover {
  transform: scale(1.04);
  box-shadow: 0 0 0 2px var(--panel-border), 0 6px 18px rgba(0, 0, 0, 0.45);
}
.zoomable:active { transform: scale(0.97); }

/* ---------- Image lightbox ---------- */

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 20, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 32px;
  cursor: zoom-out;
  animation: fadeIn 0.12s ease;
}
.lightbox-overlay.hidden { display: none; }

#lightboxImage {
  max-width: min(85vw, 480px);
  max-height: 80vh;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: 0 16px 60px rgba(0, 0, 0, 0.7);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.confirm-name { margin: 0; font-weight: 700; font-size: 1.05rem; }
.confirm-category {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.confirm-question {
  padding: 10px 16px 4px;
  margin: 0;
  color: var(--text-dim);
  font-size: 0.88rem;
}

.modal-actions {
  display: flex;
  gap: 10px;
  padding: 14px 16px 18px;
}

.btn {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--panel-border-dim);
  background: transparent;
  color: var(--text-main);
  font-size: 0.92rem;
  cursor: pointer;
}
.btn-primary {
  background: var(--panel-border);
  border-color: var(--panel-border);
  color: #061020;
  font-weight: 700;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary:hover { border-color: var(--panel-border); }

.end-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  margin: 14px 0 4px;
}
.end-stats div {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.end-stats span { font-size: 1.3rem; font-weight: 700; color: var(--gold); }
.end-stats label { font-size: 0.65rem; color: var(--text-dim); text-transform: uppercase; margin-top: 2px; }

/* ---------- Guess detail modal ---------- */

.detail-window { max-width: 460px; }
.detail-body { padding-bottom: 10px; }

.detail-numeric {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 6px;
  padding: 0 16px;
}
.detail-numeric .tile { min-height: 52px; }

.detail-sections {
  padding: 12px 16px 4px;
  max-height: 340px;
  overflow-y: auto;
}

.detail-section { margin-bottom: 12px; }
.detail-section:last-child { margin-bottom: 0; }

.detail-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 0 0 6px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
}
.tag-match { background: var(--correct); color: #04231a; }
.tag-miss { background: var(--wrong); color: #fff; }
.tag-empty { color: var(--text-dim); font-size: 0.82rem; }

/* ---------- Legal page ---------- */

.legal-page {
  max-width: 640px;
  margin: 40px auto;
  padding: 28px 24px 32px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border-dim);
  border-radius: 8px;
}

.legal-title {
  font-family: var(--font-display);
  color: var(--gold);
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  margin: 0 0 4px;
  letter-spacing: 0.04em;
}

.legal-updated {
  color: var(--text-dim);
  font-size: 0.78rem;
  margin: 0 0 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--panel-border-dim);
}

.legal-section { margin-bottom: 22px; }
.legal-section h2 {
  color: var(--gold);
  font-size: 1rem;
  margin: 0 0 8px;
}
.legal-section p {
  margin: 0 0 10px;
  line-height: 1.55;
  font-size: 0.92rem;
  color: var(--text-main);
}
.legal-section a { color: var(--panel-border); }

.legal-back {
  display: inline-block;
  width: auto;
  flex: none;
  padding: 10px 18px;
  margin-top: 8px;
  text-decoration: none;
}

/* ---------- Reset timer ---------- */

.reset-timer {
  max-width: 640px;
  margin: 32px auto 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.reset-timer #resetTimerValue {
  font-family: var(--font-mono, "Courier New", monospace);
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.05em;
}

/* ---------- Footer ---------- */

.site-footer {
  max-width: 640px;
  margin: 40px auto 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.72rem;
}
.site-footer p { margin: 4px 0; }
.site-footer a {
  color: var(--panel-border);
  text-decoration: none;
}
.site-footer a:hover { text-decoration: underline; }
