/* NEVIL OS — 80s screen, black + lavender neon */
@font-face {
  font-family: "VT323"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(../fonts/vt323-latin-400-normal.woff2) format("woff2");
}
@font-face {
  font-family: "Plex Thai"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(../fonts/ibm-plex-sans-thai-thai-400-normal.woff2) format("woff2");
  unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: "Plex Thai"; font-style: normal; font-weight: 600; font-display: swap;
  src: url(../fonts/ibm-plex-sans-thai-thai-600-normal.woff2) format("woff2");
  unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: "Plex Thai"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(../fonts/ibm-plex-sans-thai-latin-400-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Plex Thai"; font-style: normal; font-weight: 600; font-display: swap;
  src: url(../fonts/ibm-plex-sans-thai-latin-600-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --ink: #050308;
  --neon: #c08cff;
  --soft: #ddc8ff;
  --grid: #24153a;
  --dim: #8f7bb0;
  --warn: #ff8cc6;
  --glow: 0 0 6px color-mix(in srgb, var(--neon) 70%, transparent), 0 0 16px color-mix(in srgb, var(--neon) 30%, transparent);
  --pixel: "VT323", "Courier New", monospace;
  --thai: "Plex Thai", "Thonburi", "Leelawadee UI", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--soft); }
body {
  font-family: var(--thai);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 20px 20px;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
input, select { font: inherit; -webkit-user-select: text; user-select: text; }

#app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: calc(var(--safe-t) + 6px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 8px) calc(var(--safe-l) + 12px);
  gap: 10px;
  max-width: 560px; margin: 0 auto;
}
main { min-height: 0; position: relative; }
.screen { height: 100%; min-height: 0; }

/* ---- shared boxes: neon frame + an offset second frame behind ---- */
.box {
  position: relative;
  border: 2px solid var(--neon);
  background: var(--ink);
  box-shadow: var(--glow), inset 0 0 24px rgba(0, 0, 0, .8);
}
.box::after {
  content: ""; position: absolute; inset: 5px -7px -7px 5px;
  border: 1px solid var(--neon); opacity: .45; z-index: -1; pointer-events: none;
}
.box-title {
  margin: 0 0 10px; font-family: var(--pixel); font-weight: 400; font-size: 26px;
  letter-spacing: .14em; color: var(--neon); text-shadow: 0 0 6px var(--neon);
}
.dim { color: var(--dim); font-size: 14px; line-height: 1.6; }
.small { font-size: 12px; }
.big { font-family: var(--pixel); font-size: 34px; letter-spacing: .14em; color: var(--neon); text-shadow: 0 0 8px var(--neon); margin: 8px 0; }
.blink { animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---- top bar ---- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--pixel); font-size: 24px; letter-spacing: .14em;
  color: var(--neon); text-shadow: 0 0 6px var(--neon);
  border-bottom: 1px solid var(--neon); padding: 2px 2px 6px;
}
.top-right { display: flex; align-items: center; gap: 10px; }
.clock { font-variant-numeric: tabular-nums; }
.chip {
  font-family: var(--pixel); font-size: 18px; letter-spacing: .1em;
  background: var(--ink); color: var(--neon); border: 1px solid var(--neon);
  padding: 2px 8px; min-height: 32px;
}
.chip[aria-pressed="true"] { background: var(--neon); color: var(--ink); text-shadow: none; }

/* ---- PET ---- */
#screen-pet { display: grid; grid-template-rows: auto 1fr auto; gap: 10px; }
.stats { padding: 10px 12px 8px; display: grid; gap: 6px; font-family: var(--pixel); }
.stat { display: grid; grid-template-columns: 62px 1fr; align-items: center; gap: 8px; }
.stat-name { font-size: 20px; letter-spacing: .12em; color: var(--neon); }
.meter {
  --v: 50; height: 14px; border: 1px solid var(--neon); padding: 2px; display: block;
}
.meter i {
  display: block; height: 100%; width: calc(var(--v) * 1%);
  background: repeating-linear-gradient(90deg, var(--neon) 0 6px, transparent 6px 8px);
  box-shadow: 0 0 6px var(--neon); transition: width .6s;
}
.meter.low i { animation: blink 0.8s steps(1) infinite; }
.stat-status { font-size: 18px; letter-spacing: .14em; color: var(--dim); text-align: right; min-height: 18px; line-height: 1; }

.stage-wrap { min-height: 0; display: grid; place-items: end center; }
#stage {
  width: 100%; height: 100%; max-height: 420px; overflow: visible;
  filter: drop-shadow(0 0 3px var(--neon)) drop-shadow(0 0 9px color-mix(in srgb, var(--neon) 40%, transparent));
  touch-action: manipulation;
}
#stage text { font-family: var(--pixel); fill: var(--neon); stroke: none; }
.rig { fill: none; stroke: var(--neon); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.props { fill: none; stroke: var(--neon); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.speech rect, .speech path { stroke: var(--neon); stroke-width: 2; }

/* props */
.note-a, .note-b { animation: float 2.8s ease-out infinite; }
.note-b { animation-delay: 1.4s; }
@keyframes float { 0% { translate: 0 10px; opacity: 0 } 20% { opacity: 1 } 100% { translate: 6px -40px; opacity: 0 } }
.spark { animation: twinkle 1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.spark.b { animation-delay: .5s; }
@keyframes twinkle { 0%,100% { transform: scale(.4); opacity: .3 } 50% { transform: scale(1); opacity: 1 } }
.z1, .z2, .z3 { animation: zz 3s ease-out infinite; opacity: 0; }
.z2 { animation-delay: 1s; } .z3 { animation-delay: 2s; }
@keyframes zz { 0% { translate: 0 0; opacity: 0 } 20% { opacity: 1 } 100% { translate: 14px -34px; opacity: 0 } }
.chew { animation: chew .32s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes chew { from { transform: scale(1, .6); } to { transform: scale(.8, 1.3); } }
.bub { animation: bub 2.6s ease-in infinite; animation-delay: var(--d); opacity: 0; transform-box: fill-box; transform-origin: center; }
@keyframes bub { 0% { translate: 0 0; scale: .4; opacity: 0 } 15% { opacity: 1; scale: 1 } 85% { opacity: 1 } 100% { translate: 4px -36px; scale: 1.15; opacity: 0 } }
.drops { transition: opacity .15s; opacity: 0; }
.stink path { animation: stink 2.4s ease-out infinite; opacity: 0; }
.stink path + path { animation-delay: 1.2s; }
@keyframes stink { 0% { translate: 0 6px; opacity: 0 } 30% { opacity: .9 } 100% { translate: 0 -16px; opacity: 0 } }
.wing { animation: flap .08s linear infinite alternate; transform-box: fill-box; transform-origin: bottom center; }
@keyframes flap { to { transform: scaleY(.3); } }

/* menu box: rows start with "* ", the chosen row is a solid bar with black text */
.menu { padding: 6px; display: grid; gap: 2px; }
.menu-item {
  display: block; width: 100%; text-align: left; background: transparent; border: 0;
  font-family: var(--pixel); font-size: 26px; letter-spacing: .16em; color: var(--soft);
  padding: 4px 10px; min-height: 44px;
}
.menu-item::before { content: "* "; color: var(--neon); }
.menu-item:active, .menu-item:focus-visible, .menu-item.on {
  background: var(--neon); color: var(--ink); outline: none; box-shadow: 0 0 10px var(--neon);
}
.menu-item:active::before, .menu-item:focus-visible::before, .menu-item.on::before { color: var(--ink); }

/* ---- tab bar ---- */
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); border: 2px solid var(--neon); box-shadow: var(--glow); background: var(--ink); }
.tabs button {
  background: transparent; border: 0; border-right: 1px solid var(--grid);
  font-family: var(--pixel); font-size: 22px; letter-spacing: .12em; color: var(--soft);
  min-height: 46px;
}
.tabs button:last-child { border-right: 0; }
.tabs button[aria-current="page"] { background: var(--neon); color: var(--ink); box-shadow: 0 0 10px var(--neon); }

/* ---- buttons ---- */
.btn {
  font-family: var(--pixel); font-size: 21px; letter-spacing: .12em;
  background: var(--ink); color: var(--neon); border: 2px solid var(--neon);
  padding: 4px 10px; min-height: 42px;
  box-shadow: 3px 3px 0 color-mix(in srgb, var(--neon) 35%, transparent);
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 color-mix(in srgb, var(--neon) 35%, transparent); }
.btn.primary { background: var(--neon); color: var(--ink); }
.btn.danger { border-color: var(--warn); color: var(--warn); box-shadow: 3px 3px 0 color-mix(in srgb, var(--warn) 35%, transparent); }
.link { background: none; border: 0; font-family: var(--pixel); font-size: 19px; letter-spacing: .12em; color: var(--dim); text-decoration: underline; padding: 8px; }

/* ---- MEMO lock ---- */
.lock { height: 100%; display: grid; place-items: center; }
.lock-box { padding: 18px 18px 10px; width: min(320px, 100%); text-align: center; }
.lock-msg { margin: 0 0 12px; font-size: 15px; color: var(--soft); min-height: 1.6em; }
.dots { display: flex; justify-content: center; gap: 14px; margin-bottom: 16px; }
.dots span { width: 16px; height: 16px; border: 2px solid var(--neon); }
.dots span.on { background: var(--neon); box-shadow: 0 0 8px var(--neon); }
.dots.bad { animation: shake .4s; }
.dots.bad span { border-color: var(--warn); }
.dots.ok span { background: var(--neon); }
@keyframes shake { 20%, 60% { translate: -8px 0 } 40%, 80% { translate: 8px 0 } }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pad button {
  font-family: var(--pixel); font-size: 30px; min-height: 54px;
  background: var(--ink); color: var(--soft); border: 1px solid var(--neon);
}
.pad button:active { background: var(--neon); color: var(--ink); }
.pad button[data-k="del"] { font-size: 20px; letter-spacing: .1em; }

/* ---- MEMO list ---- */
.memo { height: 100%; display: grid; grid-template-rows: auto auto 1fr; gap: 10px; min-height: 0; }
.memo-tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.memo-tools .btn { padding: 4px 2px; font-size: 19px; }
.sum { display: grid; gap: 4px; font-family: var(--pixel); font-size: 19px; letter-spacing: .06em; color: var(--dim); }
.sum:empty { display: none; }
.sum-row { display: grid; grid-template-columns: 44px 1fr 1fr 1fr; gap: 6px; border-bottom: 1px dashed var(--grid); }
.sum-row b { color: var(--neon); font-weight: 400; }
.items {
  list-style: none; margin: 0; padding: 2px 8px 8px 2px; overflow-y: auto; min-height: 0;
  display: grid; align-content: start; gap: 10px; -webkit-overflow-scrolling: touch;
}
.item {
  display: grid; grid-template-columns: 46px 1fr auto; gap: 10px; align-items: center;
  border: 1px solid var(--neon); background: var(--ink); padding: 8px 10px; cursor: pointer;
}
.item:active { background: #120a1f; }
.item-day { font-family: var(--pixel); font-size: 34px; line-height: 1; color: var(--neon); text-align: center; }
.item-main { min-width: 0; display: grid; }
.item-name { font-weight: 600; font-size: 16px; line-height: 1.4; overflow-wrap: anywhere; }
.item-note { font-size: 13px; color: var(--dim); line-height: 1.4; overflow-wrap: anywhere; }
.item-amt { font-family: var(--pixel); font-size: 22px; text-align: right; line-height: 1.05; display: grid; justify-items: end; white-space: nowrap; }
.item .tag { font-size: 15px; letter-spacing: .1em; color: var(--dim); }
.item.in .tag { color: var(--neon); }
.item .due { font-size: 15px; letter-spacing: .1em; background: var(--neon); color: var(--ink); padding: 0 4px; margin-top: 2px; }
.item.soon {
  border-width: 2px;
  box-shadow: 0 0 10px var(--neon), 0 0 24px color-mix(in srgb, var(--neon) 45%, transparent), inset 0 0 14px color-mix(in srgb, var(--neon) 25%, transparent);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 4px var(--neon), 0 0 10px color-mix(in srgb, var(--neon) 30%, transparent), inset 0 0 6px color-mix(in srgb, var(--neon) 15%, transparent); } }
.empty { color: var(--dim); text-align: center; padding: 30px 10px; font-size: 15px; }

/* ---- REMOTE / SETTINGS ---- */
#screen-remote, #screen-set { overflow-y: auto; padding: 4px 8px 8px 2px; }
.soon-box { padding: 26px 18px; text-align: center; margin-top: 20px; }
.settings { padding: 16px; display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-size: 15px; }
.field select {
  width: 100%; background: var(--ink); color: var(--soft); border: 1px solid var(--neon);
  padding: 8px; font-size: 15px; font-family: var(--thai);
}
.range { display: grid; grid-template-columns: 1fr 52px; gap: 10px; align-items: center; }
.range input { accent-color: var(--neon); width: 100%; }
.range output { font-family: var(--pixel); font-size: 22px; color: var(--neon); text-align: right; }
.row-btns { display: flex; gap: 10px; }
.settings p { margin: 0; }

/* ---- dialog ---- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 16px);
  background: rgba(5, 3, 8, .82);
}
.modal-box { width: min(420px, 100%); max-height: 100%; overflow-y: auto; padding: 16px; }
.modal-body p { margin: 0 0 10px; font-size: 15px; line-height: 1.6; }
.modal-body .warn { color: var(--warn); }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: 14px; color: var(--dim); }
.form input[type=text], .form input[type=number], .form select {
  background: var(--ink); color: var(--soft); border: 1px solid var(--neon); padding: 8px 10px;
  font-size: 16px; font-family: var(--thai); width: 100%; border-radius: 0;
}
.form input:focus, .form select:focus { outline: none; box-shadow: 0 0 8px var(--neon); }
.row2 { display: grid; grid-template-columns: 1fr 100px; gap: 10px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--neon); }
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 6px; font-family: var(--pixel); font-size: 20px; letter-spacing: .08em; color: var(--soft); }
.seg input:checked + span { background: var(--neon); color: var(--ink); }
.form-err { color: var(--warn); margin: 0; min-height: 1.2em; font-size: 14px; }

/* ---- PLAY mini game ---- */
.game-box { width: min(420px, 100%); height: min(640px, 100%); display: grid; grid-template-rows: auto 1fr auto auto; padding: 12px; }
.game-top { display: flex; justify-content: space-between; font-family: var(--pixel); font-size: 22px; letter-spacing: .12em; color: var(--neon); }
.game-top b { font-weight: 400; color: var(--soft); }
.game-field { position: relative; overflow: hidden; touch-action: none; margin-top: 8px; }
.game-floor { height: 0; border-top: 2px dashed var(--neon); opacity: .6; }
.game-msg { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 6px; text-align: center; }
.game-msg p { margin: 0; }
.note {
  position: absolute; top: 0; width: 64px; height: 64px; padding: 8px; border: 0; background: transparent;
  color: var(--neon); filter: drop-shadow(0 0 4px var(--neon));
}
.note svg { width: 100%; height: 100%; overflow: visible; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.note.got { animation: got .3s ease-out forwards; }
.note.miss { animation: miss .3s ease-out forwards; color: var(--warn); }
@keyframes got { to { scale: 1.8; opacity: 0; } }
@keyframes miss { to { opacity: 0; } }

/* ---- start screen ---- */
.boot {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; cursor: pointer;
  background: var(--ink); transition: opacity .35s; outline: none;
}
.boot.gone { opacity: 0; pointer-events: none; }
.boot-inner { text-align: center; font-family: var(--pixel); color: var(--neon); text-shadow: 0 0 8px var(--neon); }
.boot-title { font-size: 64px; letter-spacing: .12em; margin: 0; }
.boot-ver { font-size: 22px; margin: 0 0 40px; color: var(--dim); text-shadow: none; }
.boot-press { font-size: 30px; letter-spacing: .2em; margin: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
