/* yakiimo-temp-monitor dashboard — 炭火 (Sumibi) theme
 * 江戸下町の焼き芋屋台 × 精密計測器
 * Shippori Mincho B1 (display) / Zen Maru Gothic (body) / Major Mono Display (data)
 */

:root {
  /* ベース: 炭の闇 */
  --color-bg-deepest:   #100a06;
  --color-bg:           #1a1410;
  --color-surface:      #23180f;
  --color-card:         #2c1f15;
  --color-card-hover:   #36281c;
  --color-border:       #3d2d1f;
  --color-border-strong:#5a4530;

  /* 炭火 ember */
  --color-ember:       #ff6b35;
  --color-ember-glow:  #ffb347;
  --color-ember-deep:  #c9312a;

  /* 紙 */
  --color-paper:        #e8d5b7;
  --color-paper-bright: #f5e6d3;
  --color-paper-muted:  #a89580;

  /* 5チャネル + 湿度・気圧の伝統色 */
  --color-ch-potato-internal: #e85a4f; /* 朱 */
  --color-ch-potato-surface:  #f5b04d; /* 山吹 */
  --color-ch-kiln-ambient:    #c9312a; /* 緋 */
  --color-ch-stone-surface:   #9ba3a8; /* 鈍色 */
  --color-ch-env:             #7a9eb1; /* 浅葱 */
  --color-ch-humidity:        #6fb3b8; /* 青磁 */
  --color-ch-pressure:        #b59cd9; /* 藤 */

  /* タイポグラフィ */
  --font-display: "Shippori Mincho B1", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --font-body:    "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", "メイリオ", sans-serif;
  --font-data:    "Major Mono Display", "Menlo", "Consolas", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  color: var(--color-paper);
  font-family: var(--font-body);
  font-feature-settings: "palt";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--color-bg);
  /* 多層 atmosphere
   * 1. 上方の ember glow
   * 2. 和紙ノイズ (SVG turbulence)
   * 3. 下方の影 */
  background-image:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(255, 107, 53, 0.12), transparent 70%),
    radial-gradient(ellipse 100% 50% at 50% 100%, rgba(0, 0, 0, 0.6), transparent 70%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.91 0 0 0 0 0.84 0 0 0 0 0.72 0 0 0 0.06 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-attachment: fixed, fixed, fixed;
  background-size: auto, auto, 240px 240px;
}

/* ---------------- Topbar ---------------- */
.topbar {
  padding: 32px 32px 24px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 20px;
  border-bottom: 1px solid var(--color-border);
  position: relative;
  animation: fade-up 600ms ease-out;
}

.topbar::after {
  content: "";
  position: absolute;
  left: 32px;
  right: 32px;
  bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg,
    transparent,
    rgba(255, 107, 53, 0.35) 30%,
    rgba(255, 179, 71, 0.35) 50%,
    rgba(255, 107, 53, 0.35) 70%,
    transparent);
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 18px;
  flex: 1 1 auto;
  min-width: 0;
}

.brand-mark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 3.4rem;
  line-height: 1;
  color: var(--color-ember);
  text-shadow:
    0 0 12px rgba(255, 107, 53, 0.45),
    0 0 28px rgba(255, 107, 53, 0.2),
    0 1px 0 rgba(0, 0, 0, 0.5);
  letter-spacing: 0;
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.06em;
  color: var(--color-paper-bright);
  line-height: 1.4;
}

/* ---------------- Live header (right of topbar) ---------------- */
.live-header {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  flex-wrap: wrap;
  animation: fade-up 600ms 80ms ease-out backwards;
  transition: border-color 300ms;
}

.live-header.mode-live {
  border-color: rgba(255, 107, 53, 0.55);
  background: linear-gradient(135deg, rgba(255, 107, 53, 0.10), var(--color-surface) 70%);
}

.live-header.mode-stale {
  border-color: rgba(245, 176, 77, 0.5);
  background: linear-gradient(135deg, rgba(245, 176, 77, 0.08), var(--color-surface) 70%);
}

.live-header.mode-offline {
  border-color: var(--color-border);
  opacity: 0.85;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-paper-muted);
  flex-shrink: 0;
}

.status-dot.live {
  background: var(--color-ember);
  animation: ember-breath 4s ease-in-out infinite;
}

.status-dot.stale {
  background: var(--color-ember-glow);
  box-shadow: 0 0 10px rgba(245, 176, 77, 0.5);
}

.status-dot.offline {
  background: var(--color-paper-muted);
  opacity: 0.55;
}

@keyframes ember-breath {
  0%, 100% {
    box-shadow:
      0 0 12px var(--color-ember),
      0 0 24px rgba(255, 107, 53, 0.4);
  }
  50% {
    box-shadow:
      0 0 20px var(--color-ember-glow),
      0 0 40px rgba(255, 179, 71, 0.6);
  }
}

.status-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.3;
}

.status-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--color-paper-bright);
}

.live-header.mode-live .status-label  { color: var(--color-ember-glow); }
.live-header.mode-stale .status-label { color: var(--color-ember-glow); }
.live-header.mode-offline .status-label { color: var(--color-paper-muted); }

.status-elapsed {
  font-family: var(--font-body);
  font-size: 0.78rem;
  color: var(--color-paper-muted);
  letter-spacing: 0.02em;
}

.live-indicator {
  font-family: var(--font-data);
  font-size: 0.72rem;
  color: var(--color-paper-muted);
  font-variant-numeric: tabular-nums;
  padding-left: 14px;
  border-left: 1px solid var(--color-border);
  margin-left: 4px;
}

/* ---------------- Main ---------------- */
main {
  flex: 1;
  padding: 36px 32px 48px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 36px;
}

/* ---------------- Current cards ---------------- */
.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}

.metric-card {
  position: relative;
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.91 0 0 0 0 0.84 0 0 0 0 0.72 0 0 0 0.04 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 22px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.4),
    0 4px 14px rgba(0, 0, 0, 0.25);
  transition:
    transform 280ms cubic-bezier(0.4, 0, 0.2, 1),
    border-color 280ms,
    box-shadow 280ms,
    background-color 280ms;
}

/* 上端 channel 色アクセントライン */
.metric-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--card-accent, var(--color-ember));
  opacity: 0.85;
}

/* 下端 subtle bar */
.metric-card::after {
  content: "";
  position: absolute;
  left: 22px;
  right: 22px;
  bottom: 10px;
  height: 1px;
  background: linear-gradient(90deg, var(--card-accent, var(--color-ember)), transparent 80%);
  opacity: 0.35;
}

.metric-card:hover {
  transform: translateY(-2px);
  border-color: var(--color-border-strong);
  background-color: var(--color-card-hover);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.4),
    0 8px 32px rgba(255, 107, 53, 0.10);
}

.metric-card.stale .card-number {
  opacity: 0.4;
}

/* 数値更新時のフラッシュ */
.metric-card.flash {
  animation: ember-flash 280ms ease-out;
}

@keyframes ember-flash {
  0%   { box-shadow: 0 0 0 1px var(--card-accent, var(--color-ember)), 0 0 18px rgba(255, 107, 53, 0.35); }
  100% { box-shadow: 0 1px 2px rgba(0,0,0,0.4), 0 4px 14px rgba(0,0,0,0.25); }
}

.card-label {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.card-icon {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--card-accent, var(--color-ember));
  text-shadow: 0 0 12px rgba(255, 107, 53, 0.18);
  flex-shrink: 0;
}

.card-name {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--color-paper);
}

.card-value {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: auto;
}

.card-number {
  font-family: var(--font-data);
  font-size: 3.2rem;
  font-weight: 400;
  line-height: 1;
  color: var(--card-accent, var(--color-ember));
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  transition: opacity 280ms;
}

.card-unit {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--color-paper-muted);
  letter-spacing: 0.04em;
}

/* card stagger fade-up */
.metric-card { animation: fade-up 600ms ease-out backwards; }
.metric-card:nth-child(1) { animation-delay: 200ms; }
.metric-card:nth-child(2) { animation-delay: 260ms; }
.metric-card:nth-child(3) { animation-delay: 320ms; }
.metric-card:nth-child(4) { animation-delay: 380ms; }
.metric-card:nth-child(5) { animation-delay: 440ms; }
.metric-card:nth-child(6) { animation-delay: 500ms; }
.metric-card:nth-child(7) { animation-delay: 560ms; }

/* ---------------- Chart ---------------- */
.chart-wrap {
  animation: fade-up 700ms 700ms ease-out backwards;
}

.chart-frame {
  position: relative;
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.0' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.91 0 0 0 0 0.84 0 0 0 0 0.72 0 0 0 0.03 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 24px;
  height: 400px;
  box-shadow:
    inset 0 1px 0 rgba(232, 213, 183, 0.04),
    0 4px 14px rgba(0, 0, 0, 0.3);
}

.chart-frame::before {
  content: "";
  position: absolute;
  top: 0;
  left: 24px;
  right: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--color-ember-deep) 50%, transparent);
  opacity: 0.4;
}

#temp-chart {
  width: 100% !important;
  height: 100% !important;
}

/* ---------------- Footer ---------------- */
.footer {
  text-align: center;
  padding: 32px 24px 40px;
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

.seal {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 0.85rem;
  letter-spacing: 0.6em;
  color: var(--color-paper-muted);
  text-indent: 0.6em; /* 字間広い分の頭合わせ */
  opacity: 0.7;
}

.meta {
  margin: 0;
  font-family: var(--font-body);
  font-size: 0.72rem;
  color: var(--color-paper-muted);
  opacity: 0.6;
  letter-spacing: 0.04em;
}

/* ---------------- Warning banner ---------------- */
.warning {
  background: linear-gradient(135deg, rgba(201, 49, 42, 0.18), rgba(201, 49, 42, 0.08));
  border: 1px solid var(--color-ember-deep);
  color: var(--color-paper-bright);
  padding: 16px 20px;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  line-height: 1.6;
}

.warning code {
  background: rgba(0, 0, 0, 0.4);
  padding: 1px 8px;
  border-radius: 4px;
  color: var(--color-ember-glow);
  font-family: var(--font-data);
  font-size: 0.85rem;
}

.warning strong {
  color: var(--color-ember-glow);
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.hidden {
  display: none !important;
}

/* ---------------- Focus / scrollbar ---------------- */
:focus-visible {
  outline: 2px solid var(--color-ember);
  outline-offset: 2px;
  border-radius: 4px;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--color-bg-deepest);
}
::-webkit-scrollbar-thumb {
  background: var(--color-ember-deep);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--color-ember);
}

/* ---------------- Animations ---------------- */
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------------- Responsive ---------------- */
@media (max-width: 1023px) {
  .cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .chart-frame { height: 350px; }
  .brand-title { font-size: 1.3rem; }
}

@media (max-width: 767px) {
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  main { padding: 24px 18px 32px; gap: 24px; }
  .topbar { padding: 24px 18px 18px; }
  .brand-mark { font-size: 2.6rem; }
  .brand-title { font-size: 1.1rem; letter-spacing: 0.04em; }
  .card-number { font-size: 2.6rem; }
}

@media (max-width: 539px) {
  .cards {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }
  .live-header {
    width: 100%;
    justify-content: flex-start;
  }
  .chart-frame { height: 280px; padding: 16px; }
  .metric-card { padding: 18px 18px 16px; }
  .card-number { font-size: 2.8rem; }
  .footer { padding: 24px 18px 32px; }
  .seal { font-size: 0.75rem; letter-spacing: 0.45em; }
}
