:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --bg2: #121821;
  --card: #161e29;
  --card2: #1b2533;
  --text: #e8eef7;
  --muted: #93a0b4;
  --line: rgba(255,255,255,.08);
  --ok: #3dd68c;
  --warn: #f5c84c;
  --bad: #ff6b7a;
  --accent: #6aa7ff;
  --radius: 14px;
  --pad: clamp(10px, 2.5vw, 20px);
  --gap: clamp(8px, 2vw, 14px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --nav-h: 58px;
  --max: 1100px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
}
body {
  padding-top: var(--safe-t);
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 8px);
}

.app {
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: var(--pad);
  padding-bottom: calc(var(--pad) + 8px);
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: calc(var(--gap) + 4px);
}
.brand { display: flex; gap: 12px; align-items: center; min-width: 0; flex: 1 1 auto; }
.mark {
  width: 36px; height: 36px; border-radius: 10px; flex: 0 0 auto;
  background: linear-gradient(135deg, #6aa7ff, #8b7bff 55%, #3dd68c);
  box-shadow: 0 0 0 1px rgba(255,255,255,.08), 0 8px 24px rgba(0,0,0,.35);
}
.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-size: clamp(1rem, 3.8vw, 1.35rem);
  line-height: 1.15;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sub { margin: 2px 0 0; color: var(--muted); font-size: clamp(.72rem, 2.8vw, .85rem); }

.top-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card2);
  color: var(--text); border-radius: 999px; padding: 8px 12px;
  font-size: .85rem; text-decoration: none; cursor: pointer;
  white-space: nowrap;
}
.btn.ghost { background: transparent; }
.btn:hover { border-color: rgba(106,167,255,.45); }

.status-grid, .cards, .links, .org {
  display: grid;
  gap: var(--gap);
}
.status-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  margin-bottom: calc(var(--gap) + 6px);
}
.card, .stat, .factory, .link {
  background: linear-gradient(180deg, var(--card), var(--bg2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  min-width: 0;
}
.stat h3, .card h3, .factory h3 {
  margin: 0 0 6px;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
}
.stat .val, .card .val {
  font-size: clamp(1rem, 4vw, 1.25rem);
  font-weight: 700;
  line-height: 1.2;
  word-break: break-word;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px; padding: 3px 8px; font-size: .72rem; font-weight: 600;
  border: 1px solid var(--line); background: rgba(255,255,255,.03);
}
.pill.ok { color: var(--ok); border-color: rgba(61,214,140,.35); }
.pill.warn { color: var(--warn); border-color: rgba(245,200,76,.35); }
.pill.bad { color: var(--bad); border-color: rgba(255,107,122,.35); }

.block { margin: 18px 0; }
.block-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin-bottom: 10px;
}
.block-head h2 { margin: 0; font-size: clamp(1rem, 3.5vw, 1.15rem); }
.hint { color: var(--muted); font-size: .75rem; text-align: right; }

.org {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
}
.factory p { margin: 6px 0; color: var(--muted); font-size: .86rem; line-height: 1.35; }
.factory .packs {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
}
.factory .packs span {
  font-size: .68rem; color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 7px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.links { grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); }
.link {
  display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: inherit;
}
.link strong { font-size: .95rem; }
.link span { color: var(--muted); font-size: .75rem; word-break: break-all; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + var(--safe-b));
  padding: 6px 4px var(--safe-b);
  background: rgba(11,15,20,.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.bottom-nav a {
  color: var(--muted); text-decoration: none; font-size: .68rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 4px 2px; min-width: 0;
}

/* Samsung Fold outer ~280css px */
@media (max-width: 320px) {
  :root { --pad: 8px; --gap: 8px; --radius: 12px; }
  .brand-text h1 { font-size: .95rem; }
  .top-actions .btn { padding: 7px 9px; font-size: .78rem; }
  .bottom-nav a { font-size: .62rem; }
  .stat .val { font-size: .95rem; }
}

/* Fold inner / large phones */
@media (min-width: 600px) and (max-width: 900px) {
  .status-grid { grid-template-columns: repeat(4, 1fr); }
  .org { grid-template-columns: repeat(2, 1fr); }
}

/* Desktop: hide bottom nav, restore padding */
@media (min-width: 901px) {
  body { padding-bottom: var(--pad); }
  .bottom-nav { display: none; }
  .org { grid-template-columns: repeat(3, 1fr); }
}

/* Prevent accidental overflow on nested flex */
img, svg, video { max-width: 100%; height: auto; }
