:root {
  color-scheme: light dark;
  --surface: #f4f8f7;
  --card: rgba(255, 255, 255, .9);
  --text: #142127;
  --muted: #617177;
  --line: rgba(27, 65, 76, .14);
  --cyan: #0b8099;
  --cyan-soft: #d8f3f8;
  --green: #1e805c;
  --danger: #a83b35;
  --shadow: 0 12px 34px rgba(30, 65, 73, .08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: radial-gradient(circle at 0 0, #dff6fa 0, transparent 38rem), var(--surface);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-underline-offset: 3px; }
button { font: inherit; }
button, a { -webkit-tap-highlight-color: rgba(11, 128, 153, .15); }
:focus-visible { outline: 3px solid #f3b040; outline-offset: 2px; }

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

.app-shell {
  width: min(1120px, 100%);
  height: 100dvh;
  min-height: 100%;
  margin-inline: auto;
  padding: env(safe-area-inset-top) clamp(12px, 3vw, 28px) env(safe-area-inset-bottom);
  display: grid;
  grid-template-rows: 62px minmax(0, 1fr);
}

.app-bar {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  min-width: 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  font-size: .96rem;
  font-weight: 750;
  letter-spacing: -.01em;
}

.brand img { width: 36px; height: 36px; object-fit: contain; }

.refresh-button {
  min-width: 84px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--text);
  background: var(--card);
  cursor: pointer;
}

.refresh-button:hover { border-color: rgba(11, 128, 153, .48); background: var(--cyan-soft); }
.refresh-button:active { transform: scale(.97); }
.refresh-button:disabled { cursor: wait; opacity: .7; }
.refresh-button.is-loading svg { animation: spin .9s linear infinite; }
.refresh-button svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

main {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 6px 0 12px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(9px, 1.8vh, 16px);
}

.summary-card {
  min-width: 0;
  min-height: 92px;
  padding: clamp(15px, 2.5vw, 24px);
  border: 1px solid rgba(11, 128, 153, .16);
  border-radius: 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(2, minmax(92px, .38fr));
  align-items: center;
  gap: clamp(14px, 4vw, 46px);
  background: linear-gradient(115deg, rgba(216, 243, 248, .94), rgba(255, 255, 255, .76));
  box-shadow: var(--shadow);
}

.summary-winner, .summary-metric { min-width: 0; display: grid; gap: 5px; }
.summary-card span { color: var(--muted); font-size: .74rem; }
.summary-card strong { min-width: 0; font-variant-numeric: tabular-nums; font-size: clamp(1.25rem, 3vw, 1.9rem); line-height: 1.05; letter-spacing: -.035em; }
.summary-winner strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.station-grid {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(9px, 1.8vw, 16px);
}

.station-card {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: clamp(16px, 2.5vw, 25px);
  border: 1px solid var(--line);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  background: var(--card);
  box-shadow: var(--shadow);
}

.station-card.is-cheapest { border-color: rgba(30, 128, 92, .52); box-shadow: 0 12px 34px rgba(30, 128, 92, .12); }
.station-card__head { min-width: 0; display: flex; align-items: center; gap: 11px; }
.station-card__head div { min-width: 0; }
.station-card__head h2, .station-card__head p { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.station-card__head h2 { font-size: clamp(.94rem, 2vw, 1.08rem); letter-spacing: -.01em; }
.station-card__head p { margin-top: 2px; color: var(--muted); font-size: .72rem; }

.station-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
}

.station-mark--petro { background: #d83b36; }
.station-mark--costco { background: #126da3; }

.primary-price {
  margin: auto 0;
  padding: clamp(10px, 2vh, 18px) 0;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.primary-price span { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.primary-price strong { font-size: clamp(2.35rem, 7vw, 4.4rem); line-height: .9; letter-spacing: -.065em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.primary-price strong small { margin-left: 4px; color: var(--muted); font-size: .72rem; font-weight: 600; letter-spacing: 0; }
.fuel-list { min-height: 34px; display: grid; }
.fuel-row { min-width: 0; padding-top: 9px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: .76rem; }
.fuel-row strong { color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }

.station-card__foot {
  min-height: 32px;
  padding-top: 8px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 9px;
  color: var(--muted);
  font-size: .7rem;
}

.station-card__foot a { min-height: 28px; display: inline-flex; align-items: center; color: var(--cyan); font-weight: 700; white-space: nowrap; }
.cheapest-badge { min-height: 25px; padding: 4px 8px; border-radius: 999px; display: inline-flex; align-items: center; color: #135f45; background: rgba(30, 128, 92, .12); font-weight: 700; white-space: nowrap; }
.station-card.is-unavailable .primary-price strong { color: var(--muted); font-size: 1.4rem; letter-spacing: -.02em; }

.status-bar {
  min-width: 0;
  min-height: 30px;
  padding-inline: 3px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: .72rem;
}

.status-bar > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-bar time { font-variant-numeric: tabular-nums; white-space: nowrap; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #f3b040; }
.status-bar.is-ready .status-dot { background: var(--green); }
.status-bar.is-error .status-dot { background: var(--danger); }

.error-panel {
  position: absolute;
  z-index: 10;
  inset: 50% auto auto 50%;
  width: min(360px, calc(100% - 28px));
  transform: translate(-50%, -50%);
  padding: 20px;
  border: 1px solid rgba(168, 59, 53, .3);
  border-radius: 18px;
  color: var(--text);
  background: var(--card);
  box-shadow: 0 24px 80px rgba(20, 33, 39, .22);
}

.error-panel[hidden] { display: none; }
.error-panel p { margin: 0 0 12px; color: var(--muted); font-size: .84rem; }
.error-panel button { min-height: 42px; border: 0; border-radius: 11px; padding: 0 16px; color: white; background: var(--danger); cursor: pointer; }

.station-card--loading .primary-price strong, .skeleton-text {
  color: transparent;
  border-radius: 8px;
  background: linear-gradient(100deg, rgba(80, 112, 120, .09) 30%, rgba(255, 255, 255, .58) 48%, rgba(80, 112, 120, .09) 66%);
  background-size: 250% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position-x: -250%; } }

@media (max-width: 560px) and (min-height: 560px) {
  .app-shell { grid-template-rows: 56px minmax(0, 1fr); }
  main { padding-top: 3px; gap: 9px; }
  .brand img { width: 32px; height: 32px; }
  .refresh-button { min-width: 44px; width: 44px; padding: 0; }
  .refresh-button span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .summary-card { min-height: 82px; padding: 12px; grid-template-columns: minmax(0, 1.25fr) repeat(2, minmax(65px, .65fr)); gap: 8px; border-radius: 16px; }
  .summary-card span { font-size: .66rem; }
  .summary-card strong { font-size: clamp(1.02rem, 5.3vw, 1.35rem); }
  .station-grid { grid-template-columns: 1fr; grid-template-rows: repeat(2, minmax(0, 1fr)); }
  .station-card { padding: 12px; border-radius: 16px; }
  .station-mark { width: 34px; height: 34px; border-radius: 10px; }
  .primary-price { padding: 7px 0; }
  .primary-price strong { font-size: clamp(2.05rem, 12vw, 3.25rem); }
  .fuel-list { min-height: 27px; }
  .fuel-row { padding-top: 6px; }
  .station-card__foot { min-height: 26px; padding-top: 4px; }
  .cheapest-badge { min-height: 22px; padding-block: 2px; }
  .status-bar { min-height: 26px; }
}

@media (max-height: 559px) {
  .app-shell { grid-template-rows: 50px minmax(0, 1fr); }
  main { padding: 2px 0 7px; gap: 6px; }
  .brand img { width: 30px; height: 30px; }
  .refresh-button { min-height: 36px; }
  .summary-card { min-height: 64px; padding: 9px 13px; border-radius: 15px; }
  .station-card { padding: 11px; border-radius: 15px; }
  .station-mark { width: 32px; height: 32px; }
  .primary-price { padding: 6px 0; }
  .primary-price strong { font-size: clamp(2rem, 7vw, 3.4rem); }
  .fuel-list { min-height: 26px; }
  .station-card__foot { min-height: 24px; padding-top: 2px; }
  .status-bar { min-height: 23px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: #10191d;
    --card: rgba(25, 38, 43, .94);
    --text: #edf5f5;
    --muted: #a8b7bb;
    --line: rgba(206, 242, 251, .13);
    --cyan: #8ad7e8;
    --cyan-soft: #173e47;
    --green: #60c89b;
    --danger: #ff9188;
    --shadow: 0 12px 34px rgba(0, 0, 0, .22);
  }
  body { background: radial-gradient(circle at 0 0, #173e47 0, transparent 38rem), var(--surface); }
  .summary-card { background: linear-gradient(115deg, rgba(23, 72, 84, .88), rgba(25, 38, 43, .88)); }
  .cheapest-badge { color: #9ce0c2; }
}

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