/* ================================================================== */
/*  CSS Variables - Day / Night theming                               */
/* ================================================================== */

:root {
  --bg-top: #d6eefb;
  --bg-bottom: #eef8ff;
  --glass: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(23, 34, 44, 0.12);
  --text: #18232d;
  --text-dim: #667986;
  --accent: #5fb5ff;
  --shadow: 0 16px 40px rgba(11, 21, 31, 0.16);
  --pixel-font: 'Courier New', ui-monospace, SFMono-Regular, Menlo, monospace;
  --ui-font: Inter, Pretendard, system-ui, sans-serif;
  --transition-speed: 0.5s;
}

/* ================================================================== */
/*  Reset & Base                                                       */
/* ================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  color: var(--text);
  font-family: var(--ui-font);
  transition: background var(--transition-speed) ease;
}

body {
  overflow: hidden;
}

button {
  font: inherit;
}

h1, h2, h3, p {
  margin-top: 0;
}

/* ================================================================== */
/*  Preloader                                                          */
/* ================================================================== */

#preloader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #1a2a3a, #0d1820);
  color: #eef4f8;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

#preloader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.preloader-content {
  text-align: center;
  max-width: 360px;
  padding: 0 24px;
}

.preloader-content h1 {
  font-size: 36px;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.preloader-content p {
  color: #9eb1bc;
  margin-bottom: 24px;
  font-size: 15px;
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #5fb5ff, #8fd1ff);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.progress-text {
  font-family: var(--pixel-font);
  font-size: 12px;
  color: #667986;
  margin: 0;
}

/* ================================================================== */
/*  App shell                                                          */
/* ================================================================== */

#app {
  min-height: 100vh;
  padding: 16px;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  transition: background var(--transition-speed) ease;
}

/* ================================================================== */
/*  Night theme                                                        */
/* ================================================================== */

#app.theme-night {
  --bg-top: #0d1420;
  --bg-bottom: #182436;
  --glass: rgba(16, 24, 40, 0.92);
  --glass-border: rgba(140, 200, 255, 0.12);
  --text: #f0f4f8;
  --text-dim: #8dafc8;
  --accent: #6cc4ff;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

/* ================================================================== */
/*  Glass morphism cards                                               */
/* ================================================================== */

.hud,
.ui-card,
.world-shell {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition:
    background var(--transition-speed) ease,
    border-color var(--transition-speed) ease,
    box-shadow var(--transition-speed) ease;
}

/* ================================================================== */
/*  HUD header                                                         */
/* ================================================================== */

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 12px 20px;
  border-radius: 16px;
  margin-bottom: 10px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 10px;
  font-family: var(--pixel-font);
  font-weight: 600;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(20px, 2.5vw, 28px);
  letter-spacing: -0.01em;
  font-family: var(--pixel-font);
  background: linear-gradient(135deg, var(--accent), #a8dcff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hud-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.chip {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: rgba(95, 181, 255, 0.08);
  color: var(--text);
  font-size: 12px;
  font-family: var(--pixel-font);
  white-space: nowrap;
  transition:
    background 0.2s ease,
    border-color 0.2s ease;
}

.button {
  cursor: pointer;
  user-select: none;
  min-width: 32px;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
}

#clockChip {
  background: rgba(95, 181, 255, 0.15);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.button:hover {
  background: rgba(95, 181, 255, 0.15);
  border-color: var(--accent);
}

.button:active {
  background: rgba(95, 181, 255, 0.25);
}

/* ================================================================== */
/*  Main shell & world container                                       */
/* ================================================================== */

.shell {
  height: calc(100vh - 126px);
}

.world-shell {
  position: relative;
  height: 100%;
  border-radius: 22px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ================================================================== */
/*  Timeline bar                                                       */
/* ================================================================== */

.timeline-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 12px 18px;
  border-bottom: 1px solid var(--glass-border);
  min-height: 52px;
  flex-shrink: 0;
}

.timeline-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  position: relative;
}

.timeline-line {
  width: 28px;
  height: 2px;
  background: var(--glass-border);
  margin: 0 2px;
  align-self: center;
  flex-shrink: 0;
  /* Vertically align with dots */
  margin-top: 14px;
}

.timeline-time {
  font-family: var(--pixel-font);
  font-size: 9px;
  color: var(--text-dim);
  line-height: 1;
}

.timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: transparent;
  transition: all 0.3s ease;
}

.dot--completed {
  background: var(--accent);
  border-color: var(--accent);
}

.dot--current {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(95, 181, 255, 0.3);
  animation: pulse-dot 1.5s ease-in-out infinite;
}

.dot--future {
  background: transparent;
  border-color: var(--glass-border);
}

.timeline-label {
  font-family: var(--pixel-font);
  font-size: 8px;
  color: var(--accent);
  white-space: nowrap;
  line-height: 1;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 3px rgba(95, 181, 255, 0.3); }
  50%      { box-shadow: 0 0 0 6px rgba(95, 181, 255, 0.1); }
}

/* ================================================================== */
/*  Viewport & canvas                                                  */
/* ================================================================== */

.viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
}

#game,
.viewport > canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #98d882;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ================================================================== */
/*  UI cards (overlays inside viewport)                                */
/* ================================================================== */

.ui-card {
  position: absolute;
  padding: 14px 16px;
  border-radius: 16px;
  max-width: min(360px, calc(100% - 24px));
  z-index: 10;
  pointer-events: auto;
}

.ui-card h2 {
  font-size: 16px;
  margin-bottom: 4px;
  line-height: 1.3;
}

.ui-card h3 {
  font-size: 15px;
  margin-bottom: 2px;
}

.ui-card p {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
  line-height: 1.45;
}

.ui-card p:last-child {
  margin-bottom: 0;
}

/* Task card */
.task-card {
  top: 14px;
  left: 14px;
  width: min(300px, calc(100% - 28px));
}

.task-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--pixel-font);
}

/* Zone card */
.zone-card {
  top: 140px;
  left: 14px;
  width: min(280px, calc(100% - 28px));
  transition: opacity 0.3s ease;
}

/* Dialog card */
.dialog-card {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(400px, calc(100% - 48px));
  z-index: 30;
  text-align: center;
}

.dialog-link {
  display: inline-block;
  margin-top: 8px;
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
  font-weight: 600;
}

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

.dialog-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.dialog-close:hover {
  color: var(--text);
}

/* NPC card */
.npc-card {
  bottom: 14px;
  left: 14px;
  width: min(240px, calc(100% - 28px));
}

.npc-card h3 {
  color: var(--text);
}

/* ================================================================== */
/*  Minimap                                                            */
/* ================================================================== */

.minimap {
  right: 14px;
  bottom: 14px;
  width: 246px;
  z-index: 10;
}

.minimap-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  color: var(--text-dim);
  font-size: 12px;
}

#minimap {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 2px solid rgba(0, 0, 0, 0.18);
  border-radius: 6px;
  background: #91cf7e;
}

/* ================================================================== */
/*  Utility                                                            */
/* ================================================================== */

.hidden {
  display: none !important;
}

/* ================================================================== */
/*  Responsive - Tablet                                                */
/* ================================================================== */

@media (max-width: 1080px) {
  body {
    overflow: auto;
  }

  .shell {
    height: auto;
  }

  .world-shell {
    min-height: 78vh;
  }

  .timeline-line {
    width: 18px;
  }
}

/* ================================================================== */
/*  Responsive - Mobile                                                */
/* ================================================================== */

@media (max-width: 760px) {
  #app {
    padding: 10px;
  }

  .hud {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 16px;
    margin-bottom: 10px;
  }

  .hud h1 {
    font-size: 24px;
  }

  .hud-actions {
    justify-content: flex-start;
    gap: 8px;
  }

  .chip {
    padding: 8px 12px;
    font-size: 12px;
  }

  .shell {
    height: auto;
  }

  .world-shell {
    min-height: auto;
    border-radius: 16px;
  }

  .timeline-bar {
    padding: 10px 12px;
    overflow-x: auto;
    justify-content: flex-start;
  }

  .timeline-line {
    width: 14px;
  }

  .viewport {
    display: flex;
    flex-direction: column;
  }

  #game,
  .viewport > canvas {
    min-height: 55vh;
    flex-shrink: 0;
  }

  /* Stack overlay cards below the canvas on mobile */
  .task-card,
  .zone-card,
  .npc-card,
  .minimap {
    position: static;
    width: calc(100% - 20px);
    max-width: 100%;
    margin: 8px 10px;
  }

  .dialog-card {
    width: calc(100% - 32px);
    top: auto;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
  }

  .minimap {
    width: calc(100% - 20px);
  }

  #minimap {
    max-height: 140px;
  }
}

/* ================================================================== */
/*  Responsive - Small mobile                                          */
/* ================================================================== */

@media (max-width: 480px) {
  #app {
    padding: 8px;
  }

  .hud {
    padding: 12px;
    border-radius: 14px;
    margin-bottom: 8px;
  }

  .hud h1 {
    font-size: 20px;
  }

  .ui-card {
    padding: 10px 12px;
    border-radius: 12px;
  }

  .ui-card h2 {
    font-size: 14px;
  }

  .ui-card p {
    font-size: 12px;
  }

  .timeline-bar {
    padding: 8px 10px;
    min-height: 44px;
  }

  .timeline-time {
    font-size: 8px;
  }

  .timeline-dot {
    width: 8px;
    height: 8px;
  }
}
