:root {
  --bg: #07080a; --bg2: #101317; --ink: #f3f5ec; --muted: rgba(243, 245, 236, .6); --faint: rgba(243, 245, 236, .1);
  --lime: #dcfe25; --lime-ink: #111404; --red: #ff8a7a;
  --display: "Chakra Petch", "IBM Plex Sans Thai", system-ui, sans-serif; --body: "IBM Plex Sans Thai", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: radial-gradient(90% 50% at 50% 0%, #161b0c, var(--bg) 60%) fixed; color: var(--ink); font: 400 15px/1.5 var(--body); }
button, input { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--display); margin: 0; }
h2 { font-size: 20px; }
h3 { font-size: 15px; margin: 18px 0 8px; color: var(--lime); }
h3 small { color: var(--muted); font-weight: 500; font-family: var(--body); }
:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }
.hint { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.err { color: var(--red); min-height: 1.4em; }

.login { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 14px; padding: 20px; text-align: center; }
.login[hidden], .app[hidden] { display: none; }
.login form { display: flex; gap: 8px; }
.login input { width: 160px; height: 54px; border-radius: 14px; border: 1px solid rgba(220, 254, 37, .35); background: var(--bg2); text-align: center; font-size: 24px; letter-spacing: .3em; }
.login button { height: 54px; padding: 0 24px; border: 0; border-radius: 14px; background: var(--lime); color: var(--lime-ink); font-weight: 700; cursor: pointer; }

.app { max-width: 1180px; margin: 0 auto; padding: 14px 14px 60px; }
.top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 6px 0 16px; }
.logo { height: 24px; }
.tag { color: var(--muted); font-size: 13px; }
.view { margin-left: auto; color: var(--lime); text-decoration: none; font-size: 14px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { padding: 14px 16px; border-radius: 16px; background: var(--bg2); border: 1px solid var(--faint); }
.stat b { display: block; font: 700 34px/1.1 var(--display); }
.stat span { color: var(--muted); font-size: 13px; }
.stat.main { grid-column: 1 / -1; background: var(--lime); color: var(--lime-ink); border-color: var(--lime); }
.stat.main span { color: rgba(17, 20, 4, .7); }
.stat.main b { font-size: 46px; }

.panel { margin-top: 14px; padding: 18px; border-radius: 20px; background: rgba(16, 19, 23, .9); border: 1px solid var(--faint); }
.row-panel { display: grid; gap: 18px; }
.switch-wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch { width: 64px; height: 36px; border-radius: 999px; border: 0; background: #3a3f45; position: relative; cursor: pointer; flex: none; transition: .2s; }
.switch span { position: absolute; top: 4px; left: 4px; width: 28px; height: 28px; border-radius: 50%; background: #fff; transition: .2s; }
.switch[aria-checked="true"] { background: var(--lime); }
.switch[aria-checked="true"] span { left: 32px; background: var(--lime-ink); }
.game-row { display: flex; gap: 8px; margin-top: 8px; }
.game-row input, .list-head input { flex: 1; min-width: 0; height: 44px; border-radius: 12px; border: 1px solid var(--faint); background: var(--bg); padding: 0 12px; }
.game-row button, .dl, .add { height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--faint); background: rgba(255, 255, 255, .06); cursor: pointer; white-space: nowrap; }
.game-wrap label { display: block; }

.calc-head { display: flex; align-items: center; gap: 12px; }
.calc-head img { object-fit: contain; }
.saved { margin-left: auto; color: var(--lime); font-size: 13px; }
.calc-grid { display: grid; gap: 18px; }
.num { display: grid; grid-template-columns: 1fr 110px 34px; align-items: center; gap: 8px; margin: 6px 0; }
.num input, .item input { height: 44px; border-radius: 10px; border: 1px solid var(--faint); background: var(--bg); padding: 0 10px; min-width: 0; }
.num input { text-align: right; }
.num em { font-style: normal; color: var(--muted); }
.items { display: grid; gap: 8px; }
.item { display: grid; grid-template-columns: 1fr 120px 40px; gap: 8px; }
.item input[type="number"] { text-align: right; }
.item button { height: 44px; border-radius: 10px; border: 1px solid var(--faint); background: none; cursor: pointer; color: var(--muted); }
.add { margin-top: 8px; width: 100%; border-style: dashed; color: var(--lime); }
.calc-out { padding: 18px; border-radius: 16px; background: var(--bg); border: 1px solid rgba(220, 254, 37, .3); align-self: start; }
.calc-out .big { font: 700 40px/1.1 var(--display); color: var(--lime); }
.calc-out .line { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--faint); font-size: 14px; }
.calc-out .line span:first-child { color: var(--muted); }
.calc-out .scen { margin-top: 18px; padding: 12px 14px; border-radius: 12px; background: rgba(255, 255, 255, .04); }
.calc-out .scen b { font-family: var(--display); font-size: 22px; }
.calc-out .lbl { font-size: 13px; color: var(--muted); }

.list-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.list-head h2 { margin-right: auto; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; order: 3; }
.tabs button { height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--faint); background: none; cursor: pointer; font-size: 14px; }
.tabs button[aria-selected="true"] { background: var(--ink); color: #0b0c0d; border-color: var(--ink); }
.list-head input { order: 4; flex-basis: 100%; }
.table-wrap { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th { text-align: left; font: 600 12px/1 var(--display); color: var(--muted); padding: 8px; letter-spacing: .05em; }
td { padding: 8px; border-top: 1px solid var(--faint); vertical-align: middle; }
.who { display: flex; align-items: center; gap: 10px; }
.who img { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; object-position: 50% 8%; background: #1a1e22; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.badge.yes { background: var(--lime); color: var(--lime-ink); }
.badge.no { background: rgba(255, 138, 122, .16); color: var(--red); }
.badge.none { background: rgba(255, 255, 255, .06); color: var(--muted); }
.del { height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--faint); background: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.del.arm { border-color: var(--red); color: var(--red); }
.time { color: var(--muted); font-size: 13px; white-space: nowrap; }

@media (min-width: 760px) {
  .stats { grid-template-columns: 1.4fr repeat(4, 1fr); }
  .stat.main { grid-column: auto; }
  .row-panel { grid-template-columns: 1fr 1.4fr; align-items: start; }
  .calc-grid { grid-template-columns: 1.2fr 1fr; }
  .tabs { width: auto; order: 0; }
  .list-head input { order: 0; flex-basis: 220px; flex: none; }
}

.stage-link { display: inline-block; margin-top: 10px; color: var(--lime); font-size: 14px; }
.testbox { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; border: 2px solid #ff8a1f; background: rgba(255, 138, 31, .1); }
.testbox h2 { color: #ffa24d; }
.testbox p { margin: 4px 0 0; }
.test-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.test-go { display: inline-flex; align-items: center; min-height: 48px; padding: 0 20px; border-radius: 12px; background: #ff8a1f; color: #1d0f00; font-weight: 700; text-decoration: none; }
.test-clear { min-height: 48px; padding: 0 16px; border-radius: 12px; border: 1px solid rgba(255, 138, 31, .6); background: none; color: #ffb066; cursor: pointer; }
.row-panel .switch-wrap + .switch-wrap { }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; padding: 12px 18px; border-radius: 999px; background: var(--ink); color: #0b0c0d; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
@media (min-width: 760px) { .row-panel { grid-template-columns: 1fr 1fr 1.4fr; } }
.testbox code { padding: 2px 6px; border-radius: 6px; background: rgba(0,0,0,.35); color: var(--ink); word-break: break-all; }

.num span small { display: block; margin-top: 2px; font-size: 12px; line-height: 1.4; color: var(--muted); }

.budget { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 12px; padding: 10px 12px; border-radius: 12px; font-weight: 700; }
.budget span { font-weight: 500; opacity: .75; }
.budget.ok { background: rgba(220, 254, 37, .12); color: var(--lime); }
.budget.over { background: rgba(255, 90, 70, .16); color: #ff8a7a; }
.budget.small { margin-top: 8px; font-size: 13px; padding: 8px 10px; }
.num { grid-template-columns: 1fr 120px 34px; }
