:root {
  --bg: #0b1220;
  --bg-elevated: #121b2e;
  --bg-card: #17223a;
  --text: #e8edf5;
  --text-dim: #93a0b8;
  --border: #26324a;
  --accent: #3fb0e0;
  --accent-2: #63d4a3;
  --danger: #e0725f;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(0,0,0,0.35);
}

[data-theme="light"] {
  --bg: #f4f6fa;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --text: #1a2233;
  --text-dim: #5b6779;
  --border: #dde3ee;
  --accent: #0d84b5;
  --accent-2: #148a5f;
  --danger: #b5402d;
  --shadow: 0 2px 10px rgba(20,30,50,0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", Roboto, sans-serif;
  line-height: 1.5;
}

body {
  padding-bottom: 2rem;
}

.en {
  font-weight: 400;
  font-size: 0.68em;
  color: var(--text-dim);
  display: inline-block;
  margin-left: 0.25em;
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 2rem);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.last-updated {
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.theme-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover { border-color: var(--accent); }

/* Layout */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 2rem);
}

.panel {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border);
}

.panel:last-child { border-bottom: none; }

.panel h2 {
  font-size: 1.05rem;
  margin: 0 0 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem;
}

.subpanel {
  margin-bottom: 1.75rem;
}

.subpanel:last-child { margin-bottom: 0; }

.subpanel h3 {
  font-size: 0.92rem;
  margin: 0 0 0.15rem;
}

.source-note {
  margin: 0 0 0.6rem;
  font-size: 0.68rem;
  color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Widget cards */
.widget-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.widget-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

.widget-card-head h3 {
  margin: 0;
  font-size: 0.88rem;
}

.widget-card-head a {
  font-size: 0.78rem;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

.widget-card-head a:hover { text-decoration: underline; }

.widget-embed {
  min-height: 60px;
}

.widget-embed iframe {
  width: 100%;
  border: 0;
  display: block;
}

.windguru-embed { min-height: 260px; padding: 0.5rem; }

.widget-embed.windy-embed iframe { height: 700px; }

.widget-embed.video-embed {
  position: relative;
  padding-top: 56.25%;
  height: 0;
}

.widget-embed.video-embed iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.widget-embed:not(.video-embed) iframe {
  height: 450px;
}

.linkout-embed {
  padding: 1rem 0.9rem 1.2rem;
}

.linkout-embed p {
  margin: 0 0 0.8rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.linkout-button {
  display: inline-block;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  background: var(--accent);
  color: #051018;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
}

/* Data blocks */
.data-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  font-size: 0.85rem;
  overflow-x: auto;
}

.data-block table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-block th, .data-block td {
  text-align: left;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-block th {
  color: var(--text-dim);
  font-weight: 600;
}

.loading { color: var(--text-dim); margin: 0; }
.error-msg { color: var(--danger); margin: 0; }

.chart-block { overflow-x: visible; padding: 0.6rem 0.7rem; }

/* Tide pager */
.tide-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 0.6rem;
}

.tide-pager-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  width: 2rem;
  height: 2rem;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.tide-pager-btn:hover:not(:disabled) { border-color: var(--accent); }
.tide-pager-btn:disabled { opacity: 0.35; cursor: default; }

.tide-day-heading {
  font-size: 0.9rem;
  font-weight: 600;
  min-width: 9rem;
  text-align: center;
}

.cwa-link {
  margin: 0.6rem 0 0;
  font-size: 0.8rem;
}

.cwa-link a {
  color: var(--accent);
  text-decoration: none;
}

.cwa-link a:hover { text-decoration: underline; }

/* Moon phase widget, overlaid top-right of the tide chart */
.tide-chart-wrap {
  position: relative;
}

.moon-widget {
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  text-align: right;
  pointer-events: none;
  user-select: none;
}

.moon-icon {
  font-size: 1.4rem;
  line-height: 1;
}

.moon-arrow {
  font-size: 0.7rem;
  margin-left: 0.15rem;
  color: var(--accent-2);
}

.moon-next {
  font-size: 0.62rem;
  color: var(--text-dim);
  margin-top: 0.1rem;
}

/* QPF image grid */
.qpf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.8rem;
}

.qpf-grid figure {
  margin: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.qpf-grid img {
  display: block;
  width: 100%;
  height: auto;
}

.qpf-grid figcaption {
  padding: 0.35rem 0.5rem;
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: center;
  border-top: 1px solid var(--border);
}

/* Buoy grid */
.buoy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.buoy-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  box-shadow: var(--shadow);
}

.buoy-card h3 {
  margin: 0 0 0.6rem;
  font-size: 0.9rem;
}

.buoy-chart-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin: 0.5rem 0 0.1rem;
}

.buoy-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 0.7rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}

.buoy-stat {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 4.5rem;
}

.buoy-stat-label {
  font-size: 0.66rem;
  color: var(--text-dim);
}

.buoy-stat-value {
  font-size: 0.88rem;
  font-weight: 600;
}

.chart-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin: 0.5rem 0 0.1rem;
}

.buoy-history-table {
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  overflow-x: auto;
}

.buoy-history-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.76rem;
}

.buoy-history-table th, .buoy-history-table td {
  text-align: left;
  padding: 0.25rem 0.4rem;
  white-space: nowrap;
  color: var(--text-dim);
}

.buoy-history-table th {
  font-weight: 600;
}

/* Placeholder */
.placeholder-block {
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
}

.placeholder-block p:first-child {
  margin: 0 0 0.4rem;
  font-size: 1rem;
  font-weight: 600;
}

.placeholder-sub {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* Footer */
.site-footer {
  max-width: 900px;
  margin: 1rem auto 0;
  padding: 1rem clamp(1rem, 4vw, 2rem) 0;
  font-size: 0.72rem;
  color: var(--text-dim);
}
