:root {
  --paper: #f4efe2;
  --card: #fffdf6;
  --ink: #14231c;
  --muted: #62705f;
  --line: #e2dac1;
  --green: #0e3f30;
  --green-2: #1b6a50;
  --gold: #c9a24b;
  --gold-d: #8c6c1c;
  --red: #b23a2a;
  --up: #1a7a4f;
  --radius: 16px;
  --display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --body: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.45 var(--body);
  padding-bottom: calc(86px + env(safe-area-inset-bottom));
}
#app { max-width: 640px; margin: 0 auto; }
h1, h2, h3 { font-family: var(--display); margin: 0; line-height: 1.15; }
h2 { font-size: 1.25rem; margin-bottom: 10px; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pos { color: var(--up); } .neg { color: var(--red); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px 20px; }
.brand { text-align: center; margin-bottom: 22px; }
.brand .seal {
  width: 74px; height: 74px; margin: 0 auto 12px; border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, #e8c872, var(--gold) 55%, var(--gold-d));
  display: grid; place-items: center; box-shadow: 0 6px 18px rgba(14, 63, 48, .25), inset 0 0 0 3px rgba(255, 255, 255, .35);
  font-family: var(--display); font-weight: 800; font-size: 2rem; color: var(--green);
}
.brand h1 { font-size: 2.3rem; color: var(--green); letter-spacing: -.01em; }
.brand p { color: var(--muted); }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: #e9e1c8; border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.seg button { border: 0; background: transparent; padding: 10px; border-radius: 9px; font: 700 .95rem var(--body); color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--green); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.linkbtn { background: none; border: 0; color: var(--muted); text-decoration: underline; font: inherit; cursor: pointer; padding: 8px; }

/* ---------- layout ---------- */
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.top .who { font-family: var(--display); font-weight: 600; color: var(--green); font-size: 1.1rem; }
.top .who small { display: block; font: 500 .75rem var(--body); color: var(--muted); }
.iconbtn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 12px; font: 600 .85rem var(--body); cursor: pointer; color: var(--green); }

.hero {
  margin: 8px 14px 16px; padding: 22px 20px 18px; border-radius: 22px; color: #f7f1dd;
  background:
    radial-gradient(circle at 85% -10%, rgba(201, 162, 75, .35), transparent 45%),
    repeating-radial-gradient(circle at 0 120%, rgba(255, 255, 255, .045) 0 2px, transparent 2px 9px),
    linear-gradient(145deg, #0e3f30, #14543f);
  box-shadow: 0 10px 28px rgba(14, 63, 48, .28); border: 2px solid rgba(201, 162, 75, .55);
}
.hero .lbl { text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; opacity: .8; }
.hero .big { font-family: var(--display); font-weight: 800; font-size: clamp(2.2rem, 11vw, 3.2rem); margin: 4px 0 10px; letter-spacing: -.02em; }
.hero .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: rgba(255, 255, 255, .12); border-radius: 999px; padding: 4px 10px; font-size: .78rem; }

main { padding: 0 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 0 rgba(0, 0, 0, .03); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.acct .k { font-size: .75rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.acct .v { font-family: var(--display); font-weight: 800; font-size: 1.5rem; margin: 2px 0; }
.bar { height: 8px; background: #eadfbd; border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--green-2), var(--gold)); border-radius: 99px; }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.row:last-child { border-bottom: 0; }
.row.total { border-top: 2px solid var(--ink); border-bottom: 0; margin-top: 4px; font-weight: 700; }
.row .memo { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row .when { font-size: .72rem; color: var(--muted); display: block; }

/* ---------- forms ---------- */
label { display: block; font-size: .8rem; font-weight: 700; color: var(--muted); margin: 10px 0 4px; letter-spacing: .02em; }
input, select {
  width: 100%; padding: 12px 12px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff;
  font: 500 1rem var(--body); color: var(--ink); min-height: 46px;
}
input:focus, select:focus { outline: 3px solid rgba(201, 162, 75, .45); border-color: var(--gold); }
.inline { display: flex; gap: 8px; align-items: stretch; }
.inline > * { flex: 1; min-width: 0; }
.inline > button { flex: 0 0 auto; }
.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; min-height: 46px; cursor: pointer;
  font: 700 1rem var(--body); background: var(--gold); color: #2a1f05;
  box-shadow: 0 2px 0 var(--gold-d); transition: transform .06s;
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.green { background: var(--green); color: #f7f1dd; box-shadow: 0 2px 0 #06241b; }
.btn.ghost { background: transparent; color: var(--green); box-shadow: none; border: 1.5px solid var(--line); }
.btn.danger { background: var(--red); color: #fff; box-shadow: 0 2px 0 #7a2418; }
.btn.sm { padding: 8px 12px; min-height: 38px; font-size: .88rem; }
.btn.block { width: 100%; margin-top: 14px; }
.btn[disabled] { opacity: .55; }
.preview { background: #f1ead3; border-radius: 10px; padding: 8px 10px; margin-top: 10px; font-size: .88rem; color: var(--ink); min-height: 36px; }

/* ---------- market ---------- */
.stock .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.stock .px { font-family: var(--display); font-weight: 800; font-size: 1.7rem; }
.stock .chg { font-size: .85rem; font-weight: 700; }
.stock svg { display: block; margin: 8px 0; width: 100%; height: 56px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
.pill { display: inline-block; background: #efe6c6; color: var(--gold-d); border-radius: 99px; padding: 2px 10px; font-size: .75rem; font-weight: 700; }
.pill.green { background: #d7ece1; color: var(--green-2); }
.pill.red { background: #f6d9d3; color: var(--red); }

/* ---------- items ---------- */
.items { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.item { border: 1.5px solid var(--line); border-radius: 14px; padding: 12px; background: #fff; display: flex; flex-direction: column; gap: 8px; justify-content: space-between; min-height: 96px; }
.item.mine { border-color: var(--gold); background: #fbf3d9; }
.item.taken { background: #f1eee3; color: var(--muted); }
.item b { font-family: var(--display); }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; background: rgba(255, 253, 246, .96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.tabbar .inner { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; width: 100%; max-width: 640px; }
.tabbar button { border: 0; background: none; padding: 8px 2px; border-radius: 12px; font: 700 .72rem var(--body); color: var(--muted); cursor: pointer; display: grid; gap: 2px; justify-items: center; }
.tabbar button svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.on { color: var(--green); background: #efe6c6; }

#toast {
  position: fixed; left: 50%; top: 14px; transform: translate(-50%, -150%); z-index: 50; max-width: min(92vw, 520px);
  background: var(--green); color: #f7f1dd; padding: 12px 16px; border-radius: 14px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); transition: transform .25s ease; border: 1.5px solid var(--gold);
}
#toast.show { transform: translate(-50%, 0); }
#toast.err { background: #fff1ee; color: #7a2418; border-color: var(--red); }

/* ---------- admin ---------- */
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 6px 4px; }
td { padding: 8px 4px; border-top: 1px solid var(--line); vertical-align: middle; }
td.r, th.r { text-align: right; }
.scroll { overflow-x: auto; }
.adminbar { background: var(--green); color: #f7f1dd; }
.adminbar .who, .adminbar .who small { color: #f7f1dd; }
.empty { text-align: center; color: var(--muted); padding: 18px 8px; }
hr { border: 0; border-top: 1px dashed var(--line); margin: 14px 0; }
