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

:root {
  --bg: #09131f;
  --card: #0f1f33;
  --card-border: rgba(255, 255, 255, 0.09);
  --text: #dce8f4;
  --muted: #6b8fad;
  --wnw: #4fc3f7;
  --ese: #ef5350;
  --warning-bg: #431407;
  --warning-text: #fdba74;
  --chart-grid: rgba(255, 255, 255, 0.07);
  --chart-border: rgba(255, 255, 255, 0.15);
  --chart-zero: rgba(255, 255, 255, 0.2);
  --nav-btn-bg: rgba(255, 255, 255, 0.07);
  --nav-btn-bg-hover: rgba(255, 255, 255, 0.13);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, 'Hiragino Sans', 'Yu Gothic UI', 'Noto Sans JP', sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Warning banner ── */
.warning-banner {
  background: var(--warning-bg);
  color: var(--warning-text);
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

/* ── Header ── */
header {
  background: var(--card);
  padding: 1rem 1.25rem 1.25rem;
  border-bottom: 1px solid var(--card-border);
  flex-shrink: 0;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-bottom: 0;
}

.theme-toggle-btn {
  background: var(--nav-btn-bg, rgba(255, 255, 255, 0.07));
  border: 1px solid var(--card-border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: background 0.15s;
  flex-shrink: 0;
}
.theme-toggle-btn:hover,
.theme-toggle-btn:active {
  background: var(--nav-btn-bg-hover, rgba(255, 255, 255, 0.13));
}

.current-speed {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
}

.speed-main {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.speed-value {
  font-size: 3.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--muted);
  transition: color 0.3s;
}
.speed-value.wnw { color: var(--wnw); }
.speed-value.ese { color: var(--ese); }

.speed-unit {
  font-size: 1rem;
  color: var(--muted);
  font-weight: 500;
}

.speed-direction {
  font-size: 1rem;
  color: var(--muted);
  font-weight: 600;
  transition: color 0.3s;
}
.speed-direction.wnw { color: var(--wnw); }
.speed-direction.ese { color: var(--ese); }

/* ── Date navigation ── */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
  background: var(--card);
  border-bottom: 1px solid var(--card-border);
  gap: 0.5rem;
  flex-shrink: 0;
}

.nav-btn {
  background: var(--nav-btn-bg, rgba(255, 255, 255, 0.07));
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  min-width: 76px;
  min-height: 44px;
  touch-action: manipulation;
  transition: background 0.15s;
}
.nav-btn:active,
.nav-btn:hover {
  background: var(--nav-btn-bg-hover, rgba(255, 255, 255, 0.13));
}
.nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.date-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
}

.date-label {
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}

.date-sub {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.today-btn {
  background: none;
  border: 1px solid var(--muted);
  color: var(--muted);
  font-size: 0.7rem;
  padding: 0.15rem 0.6rem;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s;
}
.today-btn:hover,
.today-btn:active {
  border-color: var(--text);
  color: var(--text);
}

.tide-name {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.12rem 0.55rem;
  border-radius: 10px;
  background: rgba(79, 195, 247, 0.12);
  color: var(--wnw);
  border: 1px solid rgba(79, 195, 247, 0.25);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.sun-times {
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

/* ── Main ── */
main {
  flex: 1;
  padding: 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

/* ── Chart ── */
.chart-wrapper {
  background: var(--card);
  border-radius: 12px;
  padding: 0.875rem 0.75rem 0.5rem;
  border: 1px solid var(--card-border);
}

.chart-container {
  position: relative;
  height: 44vh;
  min-height: 220px;
  max-height: 380px;
}

.chart-hint {
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.4rem;
}

/* ── Error ── */
.error {
  background: #3b0a0a;
  border: 1px solid #ef4444;
  color: #fca5a5;
  padding: 1rem 1.25rem;
  border-radius: 10px;
  text-align: center;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ── Tabs ── */
.tab-panel {
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--card-border);
  overflow: hidden;
}

.tab-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--card-border);
}

.tab-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.75rem 0.5rem;
  min-height: 44px;
  cursor: pointer;
  touch-action: manipulation;
  position: relative;
  transition: color 0.15s;
  letter-spacing: 0.02em;
}
.tab-btn::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 10%;
  right: 10%;
  height: 2px;
  background: var(--wnw);
  border-radius: 2px 2px 0 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.tab-btn.active {
  color: var(--text);
}
.tab-btn.active::after {
  opacity: 1;
}
.tab-btn:not(.active):hover {
  color: var(--text);
}

.tab-content {
  display: none;
  padding: 1rem 1.25rem;
}
.tab-content.active {
  display: block;
}

/* ── Slack tides (タブ内) ── */

#slack-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

#slack-list li {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--card-border);
}
#slack-list li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
#slack-list li:first-child {
  padding-top: 0;
}

.slack-time {
  font-size: 1.4rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  min-width: 3.2rem;
}

.slack-arrow {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

.no-data {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0.25rem 0;
}

/* ── MIRC image ── */
.mirc-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.mirc-time {
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.mirc-body {
  display: flex;
  justify-content: center;
  min-height: 80px;
  align-items: center;
}

#mirc-image {
  width: 100%;
  max-width: 480px;
  height: auto;
  border-radius: 8px;
}

.mirc-error,
.mirc-loading {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  padding: 1rem 0;
}

.mirc-source {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.6rem;
}

.mirc-source a {
  color: var(--wnw);
  text-decoration: none;
}
.mirc-source a:hover {
  text-decoration: underline;
}

/* ── Footer ── */
footer {
  text-align: center;
  padding: 1.25rem 1rem;
  font-size: 0.72rem;
  color: var(--muted);
  border-top: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

footer a {
  color: var(--wnw);
  text-decoration: none;
}
footer a:hover {
  text-decoration: underline;
}

.footer-note {
  opacity: 0.7;
}

/* ── Light mode ── */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef3f8;
    --card: #ffffff;
    --card-border: rgba(0, 0, 0, 0.09);
    --text: #162032;
    --muted: #5a7a9a;
    --warning-bg: #fef3c7;
    --warning-text: #92400e;
    --chart-grid: rgba(0, 0, 0, 0.07);
    --chart-border: rgba(0, 0, 0, 0.12);
    --chart-zero: rgba(0, 0, 0, 0.15);
    --nav-btn-bg: rgba(0, 0, 0, 0.05);
    --nav-btn-bg-hover: rgba(0, 0, 0, 0.1);
  }
}

:root[data-theme="light"] {
  --bg: #eef3f8;
  --card: #ffffff;
  --card-border: rgba(0, 0, 0, 0.09);
  --text: #162032;
  --muted: #5a7a9a;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  --chart-grid: rgba(0, 0, 0, 0.07);
  --chart-border: rgba(0, 0, 0, 0.12);
  --chart-zero: rgba(0, 0, 0, 0.15);
  --nav-btn-bg: rgba(0, 0, 0, 0.05);
  --nav-btn-bg-hover: rgba(0, 0, 0, 0.1);
}

/* ── Tablet+ ── */
@media (min-width: 640px) {
  h1 { font-size: 1.3rem; }

  .chart-container {
    height: 50vh;
    max-height: 480px;
  }

  main {
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
    padding: 1.25rem;
  }

  header {
    padding: 1.25rem 1.5rem 1.5rem;
  }

  .header-top,
  .current-speed {
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
  }

  .date-nav {
    padding: 0.75rem 1.25rem;
  }
}
