/* ============================================================
   History Explorer — history.css
   Covers both index.php (selection screen) and timeline.php
   Mobile-first; desktop overrides via min-width media queries
   ============================================================ */

/* ---- Site CSS variable fallbacks (replicated for pages that
        don't load /css/style.css directly) ---- */
:root {
  --color-bg:         #FAFBFC;
  --color-primary:    #2563EB;
  --color-accent:     #F59E0B;
  --color-text:       #1F2937;
  --color-text-muted: #6B7280;
  --color-border:     #E5E7EB;
  --color-card:       #FFFFFF;
  --radius:           8px;

  /* App-specific tokens */
  --header-h:     56px;
  --control-h:    64px;
  --transport-btn-size: 48px;
}

/* ---- Reset / base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

a { color: var(--color-primary); text-decoration: none; }
a:hover, a:focus { text-decoration: underline; }

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
}

/* ============================================================
   INDEX / SELECTION SCREEN
   ============================================================ */

.history-page {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---- Page header ---- */
.hist-header {
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.hist-header .back-link {
  font-size: 0.9rem;
  color: var(--color-primary);
  white-space: nowrap;
}

.hist-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  flex: 1;
  text-align: center;
}

/* Desktop: larger header */
@media (min-width: 768px) {
  .hist-header h1 { font-size: 1.7rem; }
}

/* ---- Main content area ---- */
.hist-main {
  flex: 1;
  padding: 20px 16px 100px; /* bottom padding for the fixed start panel */
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.hist-main h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 16px;
}

/* ---- Type card grid ---- */
.type-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

@media (min-width: 600px) {
  .type-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 900px) {
  .type-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ---- Individual type card ---- */
.type-card {
  background: var(--color-card);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  padding: 18px 12px 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline-offset: 3px;
}

.type-card:hover,
.type-card:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
  outline: none;
}

.type-card:active { transform: scale(0.97); }

.type-card.selected {
  border-color: var(--color-primary);
  background: #EFF6FF;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.18);
}

.type-card .card-icon {
  font-size: 2.2rem;
  line-height: 1;
  margin-bottom: 10px;
}

.type-card .card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 6px;
  line-height: 1.3;
}

.type-card .card-desc {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  line-height: 1.4;
}

/* Desktop: more spacious cards */
@media (min-width: 768px) {
  .type-card { padding: 24px 16px 18px; }
  .type-card .card-icon { font-size: 2.8rem; }
  .type-card .card-title { font-size: 1.05rem; }
  .type-card .card-desc { font-size: 0.85rem; }
}

/* ---- Start panel (slides in from bottom) ---- */
.start-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-card);
  border-top: 2px solid var(--color-primary);
  padding: 16px 20px 20px;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
  transform: translateY(110%);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 100;
}

.start-panel.visible {
  transform: translateY(0);
}

.start-panel-inner {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.start-panel .panel-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.start-panel .selected-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-text);
}

.year-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.year-input-row label {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.year-input-row input[type="number"] {
  width: 110px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  color: var(--color-text);
  background: var(--color-bg);
}

.year-input-row input[type="number"]:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.btn-explore {
  width: 100%;
  padding: 14px;
  background: var(--color-primary);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: var(--radius);
  transition: background 0.2s ease, transform 0.1s ease;
  letter-spacing: 0.03em;
}

.btn-explore:hover { background: #1d4ed8; }
.btn-explore:active { transform: scale(0.98); }

/* Desktop: panel is a row layout */
@media (min-width: 600px) {
  .start-panel-inner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  .btn-explore { width: auto; min-width: 160px; padding: 13px 28px; }
}

/* ---- Loading / error states (index) ---- */
.state-msg {
  text-align: center;
  padding: 48px 16px;
  color: var(--color-text-muted);
  font-size: 1rem;
}

.state-msg.error { color: #dc2626; }

/* ---- Spinner ---- */
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  display: inline-block;
  width: 36px;
  height: 36px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ============================================================
   TIMELINE SCREEN
   ============================================================ */

/* The entire app fills the viewport — no scrolling */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--color-bg);
}

/* ---- Header bar ---- */
#header-bar {
  flex: 0 0 var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  gap: 8px;
  z-index: 10;
}

#back-link {
  font-size: 0.9rem;
  color: var(--color-primary);
  white-space: nowrap;
  flex-shrink: 0;
}

#type-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
  text-align: center;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#year-display {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--color-primary);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 80px;
  text-align: right;
}

@media (min-width: 768px) {
  :root { --header-h: 60px; }
  #type-name { font-size: 1.2rem; }
  #year-display { font-size: 1.35rem; min-width: 100px; }
}

/* ---- Main area ---- */
#main-area {
  flex: 1;
  display: flex;
  flex-direction: column; /* mobile: stacked */
  overflow: hidden;
  min-height: 0;
}

/* Mobile: map gets ~52dvh, image gets remaining */
#map-panel {
  flex: 0 0 52dvh;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}

#image-panel {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #111;
  min-height: 0;
}

/* Desktop: side by side */
@media (min-width: 768px) {
  #main-area { flex-direction: row; }

  #map-panel {
    flex: 0 0 55%;
    height: 100%;
  }

  #image-panel {
    flex: 1;
    height: 100%;
  }
}

/* ---- Image container (absolute-stacked images) ---- */
#image-container {
  position: absolute;
  inset: 0;
  bottom: 44px; /* leave room for caption */
}

#image-container img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.4s ease;
  opacity: 0;
}

/* Caption bar */
#image-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 44px;
  line-height: 44px;
  padding: 0 12px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  z-index: 5;
}

/* No-data placeholder */
#image-panel .no-data-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  background: #1a1a1a;
}

/* ---- Control bar ---- */
#control-bar {
  flex: 0 0 var(--control-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--color-card);
  border-top: 1px solid var(--color-border);
  z-index: 10;
}

@media (min-width: 768px) {
  :root { --control-h: 68px; }
  #control-bar { gap: 14px; padding: 0 20px; }
}

/* Transport buttons group */
#transport-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

#transport-controls button {
  width: var(--transport-btn-size);
  height: var(--transport-btn-size);
  border-radius: var(--radius);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
  background: transparent;
  transition: background 0.15s ease, color 0.15s ease;
  border: 1px solid var(--color-border);
}

#transport-controls button:hover {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

#transport-controls button:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

#btn-play {
  font-size: 1.3rem;
  width: 52px;
  height: 52px;
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary) !important;
}

#btn-play:hover { background: #1d4ed8; }

/* Seekbar wrapper */
#seekbar-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

#seekbar-wrap span {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

#seekbar {
  flex: 1;
  min-width: 0;
  height: 6px;
  cursor: pointer;
  accent-color: var(--color-primary);
}

/* Speed selector */
#speed-select {
  padding: 6px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  flex-shrink: 0;
}

#speed-select:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

/* ---- Loading overlay ---- */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(250, 251, 252, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 1000;
  transition: opacity 0.3s ease;
}

#loading-overlay p {
  font-size: 1rem;
  color: var(--color-text-muted);
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ---- Kingdom map labels ---- */
.kingdom-label {
  background: transparent !important;
  border: none !important;
}

.kingdom-label span {
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  font-weight: 600;
}

/* Fade transition helper */
.fade-enter {
  animation: fadeIn 0.3s ease forwards;
}

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