@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap');
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: #0f172a;
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 12px;
  font-family: 'Courier New', monospace;
}

/* ── SHELL ── */
.shell {
  background: linear-gradient(170deg, #1e2235 0%, #151825 60%, #0d0f1a 100%);
  border-radius: 14px 14px 32px 32px;
  padding: 14px 14px 22px;
  width: 360px;
  box-shadow: 0 24px 64px rgba(0,0,0,.95), inset 0 1px 0 rgba(255,255,255,.07), 0 0 0 1.5px rgba(255,255,255,.04);
}

.brand {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 3px 8px;
  border-bottom: 1px solid rgba(255,255,255,.04);
  margin-bottom: 12px;
}
.brand-ti    { color: #60a5fa; font-size: 16px; font-weight: 900; letter-spacing: 5px; }
.brand-model { color: #475569; font-size: 8px; letter-spacing: 1.5px; }

/* ── LCD ── */
.lcd-housing {
  background: #06080f;
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 12px;
  border: 2px solid #030408;
  box-shadow: inset 0 4px 18px rgba(0,0,0,.98);
}
.lcd-statusbar {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  padding: 0 2px;
}
.badge {
  font-size: 7px;
  padding: 1px 5px;
  border-radius: 2px;
  letter-spacing: .8px;
  background: #0a0c14;
  color: #2d3a4a;
  transition: all .2s;
}
.badge.lit    { color: #60a5fa; background: #0c1a2e; }
.badge.lit-g  { color: #4ade80; background: #071810; }
canvas#screen {
  display: block;
  width: 100%;
  border-radius: 3px;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* ── BUTTONS ── */
.btns { display: flex; flex-direction: column; gap: 4px; }

.row-block { position: relative; padding-top: 12px; margin-bottom: 3px; }
.lbl-row {
  position: absolute; top: 0; left: 0; right: 0;
  display: grid; gap: 3px;
  font-size: 6px; color: #2563eb; text-align: center;
  pointer-events: none;
}
.lbl-row span { overflow: hidden; white-space: nowrap; }

.row { display: grid; gap: 3px; }
.r5  { grid-template-columns: repeat(5, 1fr); }
.r4  { grid-template-columns: repeat(4, 1fr); }

.btn {
  border: none; cursor: pointer; border-radius: 4px;
  font-family: 'Courier New', monospace;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 31px; padding: 3px 2px;
  transition: transform .07s, filter .07s;
  position: relative; outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:active { transform: translateY(2px) scale(.93); filter: brightness(1.5); box-shadow: none !important; }
.btn-label { font-size: 5.5px; color: #2563eb; position: absolute; top: -10px; width: 100%; text-align: center; white-space: nowrap; pointer-events: none; }
.bm  { font-size: 10px; color: #e2e8f0; font-weight: 700; line-height: 1; pointer-events: none; }
.bs  { font-size: 6.5px; color: #94a3b8; line-height: 1.1; pointer-events: none; }

.dg { background: linear-gradient(180deg,#374151,#1f2937); box-shadow: 0 3px 0 #0d1117; }
.g  { background: linear-gradient(180deg,#4b5563,#374151); box-shadow: 0 3px 0 #1c2430; }
.bl { background: linear-gradient(180deg,#2563eb,#1d4ed8); box-shadow: 0 3px 0 #1e3a8a; }
.gr { background: linear-gradient(180deg,#16a34a,#166534); box-shadow: 0 3px 0 #14532d; }
.te { background: linear-gradient(180deg,#0d9488,#0f766e); box-shadow: 0 3px 0 #134e4a; }
.bk { background: linear-gradient(180deg,#1e293b,#0f172a); box-shadow: 0 3px 0 #020617; }
.rd { background: linear-gradient(180deg,#dc2626,#b91c1c); box-shadow: 0 3px 0 #7f1d1d; }

/* ── DPAD ── */
.dpad-area  { display: flex; gap: 6px; align-items: center; margin: 3px 0; }
.dpad       { display: grid; grid-template-columns: 29px 29px 29px; grid-template-rows: 29px 29px 29px; gap: 2px; }
.dpad .btn  { min-height: 27px; min-width: 27px; padding: 0; }
.du { grid-column:2;grid-row:1; }
.dl { grid-column:1;grid-row:2; }
.dc { grid-column:2;grid-row:2; }
.dr { grid-column:3;grid-row:2; }
.dd { grid-column:2;grid-row:3; }
.dc .bm { font-size: 7px; }
.sidebuts { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }

/* ── OVERLAY PANEL ── */
.screen-wrap { position: relative; }

.panel {
  display: none;
  position: absolute;
  top: 0; left: 0; right: 0;
  background: #090c18;
  border: 1px solid #1e2d40;
  border-radius: 6px;
  padding: 11px;
  z-index: 100;
  max-height: 460px;
  overflow-y: auto;
}
.panel.open { display: block; }
.panel::-webkit-scrollbar { width: 3px; }
.panel::-webkit-scrollbar-thumb { background: #1e2d40; border-radius: 2px; }
.ptitle {
  font-size: 10px; font-weight: 700; color: #60a5fa;
  letter-spacing: 2px; border-bottom: 1px solid #1e2d40;
  padding-bottom: 6px; margin-bottom: 8px;
}

.panel label {
  display: block; font-size: 9px; color: #64748b;
  margin-top: 6px; margin-bottom: 2px;
}
.panel input[type=text],
.panel input[type=number] {
  width: 100%; background: #04060e; border: 1px solid #1e2d40;
  color: #86efac; padding: 5px 8px; border-radius: 3px;
  font-family: 'Courier New', monospace; font-size: 11px;
  margin-bottom: 2px;
}
.panel input:focus { outline: 1.5px solid #3b82f6; border-color: #3b82f6; }

.pg2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pg3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 5px; }

.pb {
  padding: 6px 4px; border: none; border-radius: 3px; cursor: pointer;
  font-family: 'Courier New', monospace; font-size: 9px; font-weight: 700;
  transition: filter .1s; color: #cbd5e1; background: #1e2d40;
}
.pb:hover { filter: brightness(1.25); }
.pb.blue  { background: #2563eb; color: #fff; }
.pb.teal  { background: #0d9488; color: #fff; }
.pb.red   { background: #dc2626; color: #fff; }

.pbrow { display: flex; gap: 5px; margin-top: 10px; }
.pbrow .pb { flex: 1; }

/* Y= rows */
.yeq-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.yeq-row input[type=text] { flex: 1; margin-bottom: 0; }
.yeq-row input[type=checkbox] { width:15px;height:15px;cursor:pointer;accent-color:#3b82f6;flex-shrink:0; }
.yeq-lbl { font-size: 11px; font-weight: 700; min-width: 28px; }

/* Table */
#tbl-result {
  max-height: 240px; overflow-y: auto; margin-top: 8px;
  background: #04060e; border-radius: 3px;
}
#tbl-result table { width: 100%; border-collapse: collapse; font-size: 9px; }
#tbl-result th { background: #0f172a; color: #60a5fa; padding: 3px 6px; border: 1px solid #1e2d40; text-align: right; position: sticky; top: 0; }
#tbl-result th:first-child { text-align: center; }
#tbl-result td { padding: 2px 6px; border: 1px solid #0d1520; color: #86efac; text-align: right; }

/* Stat */
#stat-result {
  margin-top: 8px; background: #04060e; border: 1px solid #1e2d40;
  border-radius: 3px; padding: 7px; font-size: 9px; color: #86efac;
  white-space: pre; min-height: 50px; max-height: 170px; overflow-y: auto;
}
canvas#stat-canvas { display: none; width: 100%; height: 130px; border-radius: 3px; margin-top: 6px; }

/* Calc */
#calc-result {
  margin-top: 8px; background: #04060e; border: 1px solid #1e2d40;
  border-radius: 3px; padding: 7px; font-size: 10px; color: #86efac;
  white-space: pre; min-height: 50px;
}

/* Trace bar */
#trace-bar {
  display: none;
  background: #0c1828; border: 1px solid #1e3d5a; border-top: none;
  padding: 4px 8px; font-size: 8px;
  border-radius: 0 0 4px 4px;
  display: none; justify-content: space-between; align-items: center;
}