/* Giờ Chơi · PWA + website. Một mã nguồn: thanh dưới trên điện thoại, thanh bên trên màn hình rộng. */
:root {
  --bg: #f4f5fa; --surface: #ffffff; --fg: #1b2133; --muted: #5a6280; --line: #dde1ec;
  --accent: #3846b8; --accent-soft: #e8eafb; --on-accent: #ffffff;
  --stop: #d23b2a; --stop-soft: #fdeae7; --ok: #1d7a4f; --ok-soft: #e1f4ea; --amber: #b86b00; --amber-soft: #fff2dc;
  --bar: #c9cfe3;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10131c; --surface: #181c29; --fg: #e6e9f4; --muted: #a2a9c4; --line: #2b3145;
    --accent: #9aa6ff; --accent-soft: #252b4d; --on-accent: #10131c;
    --stop: #ff6f5e; --stop-soft: #3b1d19; --ok: #5fd39a; --ok-soft: #173326; --amber: #f0b45a; --amber-soft: #3a2a12;
    --bar: #39405a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.pad { padding: 16px; }
.small { font-size: .86rem; }
.num { font-variant-numeric: tabular-nums; }

.layout { display: block; }
.side { display: none; }
main { max-width: 760px; margin: 0 auto; padding: env(safe-area-inset-top, 0px) max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 10px; gap: 12px; }
.top h1 { font-size: 1.75rem; margin: 0; letter-spacing: -.01em; }
.gear { color: var(--muted); padding: 8px; border-radius: 10px; display: inline-flex; }
.view { display: flex; flex-direction: column; gap: 14px; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px)); z-index: 20; }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; color: var(--muted); text-decoration: none; padding: 4px 0; }
.tabs a .ico { font-size: 1.1rem; line-height: 1; }
.tabs a.on { color: var(--accent); font-weight: 600; }

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .tabs, .gear { display: none; }
  .layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
  .side { display: flex; flex-direction: column; gap: 2px; padding: 20px 12px; border-right: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; height: 100vh; }
  .side .brand { font-weight: 700; font-size: 1.15rem; padding: 4px 12px 16px; }
  .side a { text-decoration: none; color: var(--fg); padding: 9px 12px; border-radius: 10px; }
  .side a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .side .who { margin-top: auto; font-size: .85rem; color: var(--muted); padding: 12px; }
  main { max-width: 980px; padding-top: 12px; }
  .wide-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; align-items: start; }
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card h2 { font-size: 1.05rem; margin: 0; }
.card h3 { font-size: .95rem; margin: 0; }
.row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; padding: 3px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.stop { background: var(--stop-soft); color: var(--stop); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.grey { background: var(--line); color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 14px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--stop); border-color: var(--stop); background: transparent; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.stop-big { background: var(--stop); border: 0; color: #fff; font-size: 1.25rem; min-height: 64px; border-radius: 18px; width: 100%; box-shadow: 0 6px 18px color-mix(in srgb, var(--stop) 30%, transparent); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cmd-line { font-size: .9rem; color: var(--muted); text-align: center; min-height: 1.3em; }

.now { display: flex; flex-direction: column; gap: 4px; }
.now .big { font-size: 1.3rem; font-weight: 700; }

.usage { display: flex; flex-direction: column; gap: 12px; }
.u-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: baseline; }
.u-item .name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-item .meta { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.u-item .track { grid-column: 1 / -1; height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.u-item .fill { height: 100%; background: var(--accent); border-radius: 99px; }
.u-item.over .fill { background: var(--stop); }
.u-item.over .meta { color: var(--stop); }
.u-item .sub { grid-column: 1 / -1; font-size: .8rem; color: var(--muted); }

.request { border: 1px solid var(--amber); background: var(--amber-soft); }
.request.flash { animation: flash 1.2s ease 2; }
@keyframes flash { 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--amber) 40%, transparent); } }

.seg { display: inline-grid; grid-auto-flow: column; background: var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }

.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; flex: none; }
.stepper button { border: 0; background: transparent; width: 40px; height: 40px; font-size: 1.2rem; color: var(--accent); }
.stepper .val { min-width: 52px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

.rule { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.rule:first-of-type { border-top: 0; }
.rule .label { flex: 1 1 140px; min-width: 0; }
.rule .label b { display: block; overflow-wrap: anywhere; }
.rule .label span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rule .label span { font-size: .8rem; color: var(--muted); }
select, input[type=text], input[type=time], input[type=password], input[type=number] { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 10px; min-height: 40px; max-width: 100%; }

.sched { display: flex; flex-direction: column; gap: 10px; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days button { width: 40px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: .85rem; font-weight: 600; color: var(--muted); }
.days button.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgb(0 0 0 / .25); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }

.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; width: 100%; min-width: 320px; height: auto; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.events li { display: grid; grid-template-columns: 4.2em 1fr; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: .92rem; }
.events li:first-child { border-top: 0; }
.events time { color: var(--muted); font-variant-numeric: tabular-nums; }

.code { font-size: 2.4rem; font-weight: 800; letter-spacing: .18em; font-variant-numeric: tabular-nums; text-align: center; padding: 8px 0; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; }

.sheet { position: fixed; inset: 0; background: rgb(0 0 0 / .4); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet .panel { background: var(--surface); width: 100%; max-width: 520px; border-radius: 20px 20px 0 0; padding: 18px max(16px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 10px; }
.sheet .opt { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.sheet .opt b { font-size: 1.05rem; }
.sheet .opt.red b { color: var(--stop); }
.sheet .opt span { font-size: .85rem; color: var(--muted); }
@media (min-width: 900px) { .sheet { align-items: center; } .sheet .panel { border-radius: 20px; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom, 0px)); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .92rem; z-index: 50; max-width: calc(100% - 32px); }
@media (min-width: 900px) { .toast { bottom: 24px; } }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); display: flex; flex-direction: column; gap: 12px; align-items: center; }
.err { color: var(--stop); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
