:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #edf1ec;
  --ink: #15201c;
  --muted: #5b6a64;
  --line: #d9e0da;
  --accent: #0b7a5f;
  --accent-ink: #ffffff;
  --accent-soft: #dcf1ea;
  --danger: #b92f26;
  --danger-ink: #ffffff;
  --danger-soft: #fbe6e3;
  --warn-soft: #fbf0d8;
  --warn-ink: #6e4a00;
  --shadow: 0 1px 2px rgb(20 30 25 / 8%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1412;
    --surface: #18201d;
    --surface-2: #222c28;
    --ink: #e9efec;
    --muted: #9aa8a2;
    --line: #2f3a36;
    --accent: #3bcba1;
    --accent-ink: #06251b;
    --accent-soft: #143329;
    --danger: #ff8176;
    --danger-ink: #300906;
    --danger-soft: #3a1a17;
    --warn-soft: #33290f;
    --warn-ink: #f0cf85;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Sinhala", "Iskoola Pota", sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

h1 { font-size: 16px; font-weight: 650; margin: 0; }
h2 { font-size: 14px; font-weight: 650; margin: 0 0 8px; }
p { margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 8px; }

main { max-width: 560px; margin: 0 auto; padding: 16px; }
.tab, #composer { display: flex; flex-direction: column; gap: 14px; }
#composer h2 { margin: 0 0 -6px; }
#composer[hidden] { display: none; }
#tab-write > .actions {
  position: sticky; bottom: calc(68px + env(safe-area-inset-bottom)); z-index: 4;
  padding: 8px 0; background: var(--bg);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.muted { color: var(--muted); font-size: 13px; }
.tnum { font-variant-numeric: tabular-nums; }
.section-head { margin-top: 10px; }
.section-head h2 { margin: 0; }

/* Type picker */
.types { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.types button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 68px; padding: 8px 4px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  font: inherit; font-size: 12.5px; line-height: 1.25; cursor: pointer;
}
.types button[aria-checked="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  font-weight: 600;
}
.types svg { width: 22px; height: 22px; }
svg path, svg rect { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Forms */
.fields { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 550; }
.field input, .field textarea, .field select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: 16px; font-weight: 400;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus-visible, .field textarea:focus-visible, .field select:focus-visible,
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 44px; cursor: pointer; }
.switch small { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; }
.switch input, .check input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; }
.batch { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.batch code, .tips code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* Preview */
.mono { font: 13px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.preview { min-height: 42px; max-height: 180px; overflow: auto; padding: 10px; background: var(--bg); border-radius: 8px; }
.preview:empty::before { content: "—"; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: var(--accent-soft); }
.chip.no { background: var(--danger-soft); color: var(--danger); text-decoration: line-through; }

/* Buttons */
button { font: inherit; cursor: pointer; }
.primary, .ghost, .danger {
  min-height: 48px; padding: 10px 16px;
  border-radius: 10px; font-weight: 600; border: 1px solid transparent;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.danger { background: var(--danger); color: var(--danger-ink); }
button:disabled { opacity: .45; cursor: not-allowed; }
.small { min-height: 36px; padding: 4px 12px; font-size: 13px; font-weight: 550; flex: none; }
.wide { width: 100%; }
.actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }

.error { color: var(--danger); font-weight: 550; }

.notice { display: flex; gap: 10px; justify-content: space-between; align-items: flex-start; border-radius: 10px; padding: 12px; font-size: 14px; }
.notice > div { min-width: 0; }
.notice.warn { background: var(--warn-soft); color: var(--warn-ink); margin: 12px 16px 0; }
.notice.info { background: var(--accent-soft); }
.notice pre { margin-top: 6px; max-height: 110px; overflow: auto; }

/* Read result, lists */
.result { display: flex; flex-direction: column; gap: 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.record { border-top: 1px solid var(--line); padding-top: 10px; }
.record h3 { font-size: 13px; margin: 0 0 4px; font-weight: 650; }
.record a { color: var(--accent); }
.record .row { margin-top: 8px; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.item .grow { flex: 1; min-width: 0; }
.item strong { display: block; overflow-wrap: anywhere; }
.item small { display: block; color: var(--muted); overflow-wrap: anywhere; }
.tool { display: flex; flex-direction: column; gap: 10px; }
.tool h2 { margin: 0; }
.danger-card { border-color: var(--danger); }
.tips { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }

/* Bottom nav */
.bottom {
  position: fixed; inset: auto 0 0 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 60px; padding: 8px 2px;
  background: none; border: 0; color: var(--muted); font-size: 12px;
}
.bottom svg { width: 22px; height: 22px; }
.bottom button[aria-current="page"] { color: var(--accent); font-weight: 650; }

/* NFC sheet */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgb(5 12 9 / 55%);
}
.sheet {
  width: 100%; max-width: 560px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 24px 20px calc(20px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  text-align: center;
}
.sheet h2 { font-size: 18px; margin: 4px 0 0; }
.sheet p { overflow-wrap: anywhere; }
.sheet .wide { margin-top: 10px; }
.mono-small { font-size: 12px; }
.mono-small:empty { display: none; }
.count { font-size: 40px; font-weight: 700; line-height: 1.1; color: var(--accent); }

.visual { position: relative; width: 120px; height: 120px; display: grid; place-items: center; color: var(--accent); }
.visual svg { width: 72px; height: 72px; position: relative; display: none; }
.visual.wait .v-card { display: block; }
.visual.ok .v-ok { display: block; }
.visual.err { color: var(--danger); }
.visual.err .v-err { display: block; }
.visual.ok svg path, .visual.err svg path { stroke-width: 4; }
.ring { position: absolute; inset: 22px; border: 2px solid var(--accent); border-radius: 50%; opacity: 0; }
.visual.wait .ring { animation: ping 2s ease-out infinite; }
.visual.wait .r2 { animation-delay: 1s; }
.visual.ok, .visual.err { border-radius: 50%; }
@keyframes ping {
  from { transform: scale(.7); opacity: .7; }
  to { transform: scale(1.5); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .visual.wait .ring { animation: none; opacity: .4; }
}

dialog {
  width: min(92vw, 420px);
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--ink);
  padding: 18px;
}
dialog::backdrop { background: rgb(5 12 9 / 55%); }
dialog h2 { font-size: 17px; }
dialog .actions { margin-top: 14px; grid-template-columns: 1fr 1fr; }

.toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 30; max-width: calc(100vw - 32px);
  background: var(--ink); color: var(--bg);
  padding: 9px 14px; border-radius: 8px; font-size: 14px;
}
