:root {
  color-scheme: dark;
  --bg: #10130f;
  --panel: #1b211a;
  --panel-2: #232b20;
  --line: #3a4434;
  --text: #eef3e8;
  --muted: #aeb8a5;
  --accent: #8fd66b;
  --accent-2: #74b7d8;
  --warn: #e5bc62;
  --shadow: rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 60% 0%, #263020 0, #11150f 44%, #0b0d0b 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  min-height: 100vh;
}

.workspace {
  min-height: 100vh;
}

.sim-pane {
  padding: 22px;
  min-width: 0;
}

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

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

.home-link {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin-bottom: 8px;
  padding: 6px 9px;
  border: 1px solid rgba(238, 243, 232, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 700;
  text-decoration: none;
}

.home-link:hover {
  border-color: rgba(143, 214, 107, 0.52);
  color: var(--accent);
  text-decoration: none;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 3vw, 2.7rem);
  font-weight: 760;
}

.topbar p {
  color: var(--muted);
  margin-top: 4px;
}

.timebox,
.metrics article,
.panel,
.controls {
  background: color-mix(in srgb, var(--panel) 92%, black);
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px var(--shadow);
}

.timebox {
  min-width: 150px;
  padding: 12px 14px;
  border-radius: 8px;
  text-align: right;
}

.timebox span,
.metrics span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.timebox strong,
.metrics strong {
  display: block;
  margin-top: 3px;
  font-size: 1.05rem;
}

.canvas-wrap {
  min-height: 420px;
  height: min(63vh, 690px);
  border: 1px solid var(--line);
  background: #070906;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.metrics article {
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}

.analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1.25fr 1fr;
  gap: 12px;
}

.panel {
  border-radius: 8px;
  padding: 14px;
  min-height: 185px;
}

.calendar-panel {
  grid-column: 1 / -1;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin-bottom: 0;
}

.panel-head strong {
  color: var(--accent);
  font-size: 0.86rem;
  white-space: nowrap;
}

.panel-note,
.control-note {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  margin: 0 0 12px;
}

.golarion-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(110px, 1fr));
  gap: 6px;
  overflow-x: auto;
}

.calendar-weekday {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.calendar-day {
  min-height: 94px;
  border: 1px solid rgba(174, 184, 165, 0.16);
  background: rgba(7, 9, 6, 0.36);
  padding: 7px;
  display: grid;
  align-content: start;
  gap: 4px;
}

.calendar-day.empty {
  border-color: transparent;
  background: transparent;
}

.calendar-day.current {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(143, 214, 107, 0.36);
}

.calendar-day.has-event {
  background: rgba(229, 188, 98, 0.1);
}

.calendar-day.strong-tide {
  border-bottom-color: var(--accent-2);
}

.calendar-day.moon-same,
.calendar-day.moon-opposed {
  border-color: var(--warn);
}

.calendar-day.magic-strong {
  box-shadow: inset 0 0 0 1px rgba(229, 188, 98, 0.34), 0 0 18px rgba(229, 188, 98, 0.08);
}

.calendar-day.moon-opposed {
  background: linear-gradient(135deg, rgba(229, 188, 98, 0.14), rgba(116, 183, 216, 0.08));
}

.calendar-day.moon-same {
  background: linear-gradient(135deg, rgba(143, 214, 107, 0.12), rgba(229, 188, 98, 0.1));
}

.calendar-date {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  align-items: center;
}

.calendar-date strong {
  color: var(--text);
}

.calendar-date span {
  display: flex;
  gap: 3px;
  color: #dfe8f8;
  font-size: 0.78rem;
}

.calendar-day small {
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.15;
}

.magic-tier.dominant {
  width: fit-content;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 6px;
  border: 1px solid color-mix(in srgb, var(--magic-color) 72%, transparent);
  border-radius: 6px;
  background: color-mix(in srgb, var(--magic-color) 18%, rgba(7, 9, 6, 0.82));
  color: var(--magic-color);
  font-weight: 800;
  overflow: hidden;
}

.magic-tier.dominant span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.magic-tier.dominant em {
  color: var(--text);
  font-style: normal;
  font-weight: 700;
  opacity: 0.9;
}

.tide-panel canvas {
  height: 260px;
}

.panel h2,
.controls h2 {
  font-size: 1rem;
  margin-bottom: 12px;
}

.bars {
  display: grid;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 48px 1fr 56px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.bar-track {
  height: 12px;
  background: #0d100c;
  border: 1px solid #34402d;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--warn), var(--accent));
}

#insights {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.45;
}

.data-guide {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.data-guide dt {
  color: var(--text);
  font-weight: 800;
}

.data-guide dd {
  margin: 0;
}

.controls {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 20;
  width: min(390px, calc(100vw - 28px));
  height: 100vh;
  overflow: auto;
  padding: 18px;
  border-width: 0 0 0 1px;
  border-radius: 0;
  transform: translateX(105%);
  transition: transform 180ms ease;
}

.controls.open {
  transform: translateX(0);
}

.control-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.control-head div {
  display: flex;
  gap: 8px;
}

button {
  appearance: none;
  border: 1px solid #526247;
  background: #283320;
  color: var(--text);
  border-radius: 6px;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.icon-button {
  width: 42px;
  min-width: 42px;
  padding: 8px;
  font-size: 1.15rem;
  line-height: 1;
}

.primary {
  min-width: 96px;
  background: #335126;
  border-color: #6ea85a;
  font-weight: 800;
}

.speed-control,
.hour-control {
  width: min(260px, 42vw);
  min-width: 210px;
  margin: 0;
  padding: 9px 12px;
  border: 1px solid #526247;
  border-radius: 8px;
  background: #11160f;
}

.speed-control input,
.hour-control input {
  margin-top: 4px;
}

.speed-unit {
  width: 96px;
  align-self: stretch;
  border: 1px solid #526247;
  background: #11160f;
  color: var(--text);
  border-radius: 8px;
  padding: 0 8px;
  font: inherit;
}

.primary.paused {
  background: #4d3321;
  border-color: var(--warn);
}

fieldset {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 8px;
  margin: 0 0 12px;
  padding: 12px;
}

.config-fieldset {
  position: sticky;
  top: 0;
  z-index: 2;
  background: color-mix(in srgb, var(--panel-2) 94%, black);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
}

legend {
  padding: 0 6px;
  color: var(--accent);
  font-weight: 700;
}

label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  margin: 10px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.text-field input,
select {
  grid-column: 1 / -1;
  min-width: 0;
  width: 100%;
  border: 1px solid #46543f;
  background: #11160f;
  color: var(--text);
  border-radius: 6px;
  padding: 8px;
  font: inherit;
}

label output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--accent);
}

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

.toggle input {
  accent-color: var(--accent);
}

.export-status {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 8px;
}

.preset-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(2, max-content 44px);
  gap: 8px 10px;
  align-items: center;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.84rem;
}

.color-grid input {
  width: 44px;
  height: 30px;
  padding: 0;
  border: 1px solid #46543f;
  background: #11160f;
  border-radius: 6px;
}

.affinity-grid {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.threshold-grid {
  display: grid;
  grid-template-columns: max-content 72px minmax(0, 1fr);
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.threshold-grid span {
  align-self: center;
}

.threshold-grid input {
  min-width: 0;
  border: 1px solid #46543f;
  background: #11160f;
  color: var(--text);
  border-radius: 6px;
  padding: 7px;
  font: inherit;
}

.affinity-grid span {
  align-self: center;
}

.affinity-grid input {
  min-width: 0;
  border: 1px solid #46543f;
  background: #11160f;
  color: var(--text);
  border-radius: 6px;
  padding: 7px;
  font: inherit;
}

.alignment-badge {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  border-radius: 999px;
  padding: 2px 6px;
  color: #10130f;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.alignment-badge.same {
  background: #e5bc62;
}

.alignment-badge.opposed {
  background: #9fd4ef;
}

.magic-tier {
  color: var(--text);
  font-weight: 800;
}

.magic-bars {
  display: grid;
  gap: 3px;
  margin-top: 2px;
}

.magic-bar {
  position: relative;
  height: 12px;
  overflow: hidden;
  border: 1px solid rgba(174, 184, 165, 0.18);
  background: rgba(7, 9, 6, 0.5);
}

.magic-bar span {
  position: relative;
  z-index: 1;
  display: block;
  padding-left: 4px;
  color: #eef3e8;
  font-size: 0.62rem;
  line-height: 10px;
}

.magic-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  background: #8fd66b;
}

.magic-bar.medium i {
  background: #74b7d8;
}

.magic-bar.strong i {
  background: #e5bc62;
}

.magic-bar.super i {
  background: #f08b63;
}

.day-strip {
  margin: 12px 0;
}

.day-strip-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.day-strip-head span {
  color: var(--muted);
  font-size: 0.86rem;
}

.sun-timeline {
  position: relative;
  height: 30px;
  border: 1px solid #3e4936;
  background: #080a08;
  overflow: hidden;
}

.sun-day {
  position: absolute;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, #c58233, #f1d56f, #c58233);
}

.sun-night {
  position: absolute;
  top: 0;
  bottom: 0;
  background: #11151d;
}

.sun-now {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: #ffffff;
  box-shadow: 0 0 10px #fff5a8;
}

.sun-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 6px;
}

.event-list,
.climate-box,
.phase-box {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.event-item,
.phase-row,
.climate-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid rgba(174, 184, 165, 0.12);
  padding-bottom: 7px;
}

.phase-row span {
  display: grid;
  gap: 3px;
}

.phase-row small {
  color: var(--muted);
  font-size: 0.74rem;
}

.phase-row.resonance {
  border-bottom-color: rgba(229, 188, 98, 0.42);
}

.phase-row.resonance strong {
  color: var(--warn);
}

.event-item strong,
.phase-row strong,
.climate-line strong {
  color: var(--text);
}

@media (max-width: 1060px) {
  .analysis-grid,
  .metrics {
    grid-template-columns: 1fr 1fr;
  }

  .calendar-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .sim-pane {
    padding: 14px;
  }

  .topbar,
  .analysis-grid,
  .metrics {
    grid-template-columns: 1fr;
    display: grid;
  }

  .timebox {
    text-align: left;
  }

  .top-actions {
    justify-content: stretch;
  }

  .speed-control,
  .hour-control,
  .timebox,
  .primary {
    width: 100%;
  }

  .golarion-calendar {
    grid-template-columns: repeat(7, minmax(72px, 1fr));
  }

  .calendar-day {
    min-height: 66px;
  }

  .data-guide {
    grid-template-columns: 1fr;
  }
}
