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

:root {
  --bg: #0c0f14;
  --surface: #151a22;
  --text: #e8ecf2;
  --text-muted: #8b95a8;
  --accent: #f5a623;
  --radius: 16px;
  --font: "DM Sans", system-ui, sans-serif;
}

html {
  font-size: 16px;
  height: 100%;
  max-height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  max-height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  line-height: 1.5;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: stretch;
}

.app {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding:
    max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.location {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: right;
  max-width: 48%;
  line-height: 1.3;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.location-icon-btn {
  font-family: var(--font);
  color: var(--accent);
  font-size: 0.9rem;
  line-height: 1;
  padding: 0.15rem;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 50%;
  transition: color 0.15s, transform 0.1s;
}

.location-icon-btn:hover {
  color: #ffc04d;
}

.location-icon-btn:active {
  transform: scale(0.92);
}

.sky-panel {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  flex: 1 1 auto;
  min-height: min(52vh, 420px);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

#sky-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.sky-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 0.35rem;
  pointer-events: none;
}

.percentage-display {
  font-size: clamp(2.25rem, 11vw, 3.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

.controls {
  margin-top: 1.25rem;
  flex-shrink: 0;
}

.time-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.current-time {
  font-size: 1.35rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.now-btn {
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(245, 166, 35, 0.4);
  background: rgba(245, 166, 35, 0.12);
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.now-btn:hover {
  background: rgba(245, 166, 35, 0.22);
  border-color: var(--accent);
}

.now-btn:active {
  transform: scale(0.97);
}

.slider-wrap {
  margin-bottom: 1.25rem;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  --sunrise-pos: 25%;
  --noon-pos: 50%;
  --sunset-pos: 75%;
  background: linear-gradient(
    90deg,
    #1a2744 0%,
    #3d5a80 calc(var(--sunrise-pos) - 4%),
    #5a7a50 var(--sunrise-pos),
    #3d5a80 calc(var(--noon-pos) - 10%),
    #f5a623 var(--noon-pos),
    #3d5a80 calc(var(--sunset-pos) - 4%),
    #5a4a30 var(--sunset-pos),
    #1a2744 100%
  );
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff8e7, var(--accent));
  box-shadow:
    0 0 0 3px rgba(245, 166, 35, 0.35),
    0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: grab;
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff8e7, var(--accent));
  box-shadow:
    0 0 0 3px rgba(245, 166, 35, 0.35),
    0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: grab;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 0.5rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

#noon-label {
  color: var(--accent);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.stat {
  background: var(--surface);
  border-radius: 12px;
  padding: 0.65rem 0.35rem;
  text-align: center;
  min-width: 0;
}

.stat-label {
  display: block;
  font-size: 0.58rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.2rem;
  line-height: 1.2;
}

.stat-value {
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

@media (min-width: 480px) {
  .stats {
    gap: 0.75rem;
  }

  .stat {
    padding: 0.75rem 0.65rem;
  }

  .stat-label {
    font-size: 0.68rem;
  }

  .stat-value {
    font-size: 0.95rem;
  }
}

.link-btn {
  font-family: var(--font);
  font-size: 0.68rem;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}

.link-btn:hover {
  color: #ffc04d;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.location-dialog {
  border: none;
  border-radius: var(--radius);
  padding: 1.25rem;
  background: var(--surface);
  color: var(--text);
  max-width: 480px;
  width: calc(100% - 2rem);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.location-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.location-dialog h2 {
  font-size: 1.1rem;
  margin-bottom: 0.35rem;
}

.map-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.location-map {
  width: 100%;
  height: 240px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--bg);
}

.map-coords {
  margin-top: 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  text-align: center;
}

.dialog-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.primary-btn,
.secondary-btn {
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  border: none;
}

.primary-btn {
  background: var(--accent);
  color: #1a1200;
}

.secondary-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

@media (min-width: 600px) {
  .app {
    max-width: 720px;
    padding:
      max(1.25rem, env(safe-area-inset-top))
      1.5rem
      max(1.25rem, env(safe-area-inset-bottom))
      1.5rem;
  }

  .sky-panel {
    min-height: min(58vh, 480px);
  }
}

@media (orientation: landscape) and (min-height: 500px) {
  .sky-panel {
    min-height: min(62vh, 440px);
  }
}

@media (min-width: 1024px) and (pointer: fine) {
  .app {
    max-width: 560px;
    padding:
      max(1rem, env(safe-area-inset-top))
      1.25rem
      max(1rem, env(safe-area-inset-bottom))
      1.25rem;
  }

  .sky-panel {
    flex: 1 1 0;
    min-height: 0;
  }

  .header {
    margin-bottom: 0.75rem;
  }

  .header h1 {
    font-size: 1.35rem;
  }

  .controls {
    margin-top: 0.75rem;
  }

  .slider-wrap {
    margin-bottom: 0.75rem;
  }

  .current-time {
    font-size: 1.2rem;
  }
}