:root {
  --luna-blue1: #0058e1;
  --luna-blue2: #3b8cff;
  --luna-face: #ece9d8;
  --luna-panel: #f4f2e8;
  --luna-green: #5eab30;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Source Sans 3', Tahoma, sans-serif;
  min-height: 100vh;
  background: linear-gradient(180deg,#4a86d6 0%, #6ba3e0 25%, #8fc44f 55%, #6ba82e 78%, #4b7a1e 100%);
}

.desktop {
  min-height: 100vh;
  padding: 24px 12px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* ---- Window chrome ---- */
.xp-window {
  width: 100%;
  max-width: 960px;
  background: var(--luna-face);
  border-radius: 8px 8px 3px 3px;
  box-shadow: 0 10px 40px rgba(0,0,0,.45);
  overflow: hidden;
  border: 1px solid #0a3e9e;
  animation: winpop .4s ease;
}
@keyframes winpop { from { transform: scale(.96); opacity:0; } to { transform: scale(1); opacity:1; } }

.xp-window.shake { animation: shake .45s ease; }
@keyframes shake {
  0%,100%{ transform: translateX(0);}
  20%{ transform: translateX(-8px);}
  40%{ transform: translateX(8px);}
  60%{ transform: translateX(-6px);}
  80%{ transform: translateX(6px);}
}

.titlebar {
  height: 30px;
  background: linear-gradient(180deg, var(--luna-blue2) 0%, var(--luna-blue1) 45%, #0043b0 100%);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px 0 8px;
  border-radius: 8px 8px 0 0;
  border-bottom: 1px solid #0033a0;
}
.titlebar-left { display: flex; align-items: center; gap: 6px; }
.winflag { font-size: 15px; }
.title-text {
  color: #fff; font-weight: 700; font-size: 13px;
  text-shadow: 1px 1px 1px rgba(0,0,0,.4);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.titlebar-btns { display: flex; gap: 3px; }
.tb-btn {
  width: 22px; height: 21px; border: 1px solid #1a4fb5;
  border-radius: 3px; color: #fff; font-weight: 700; font-size: 11px;
  cursor: pointer; line-height: 1;
  background: linear-gradient(180deg,#5c9bff,#2b6ee0);
}
.tb-btn.close { background: linear-gradient(180deg,#f79070,#d5442a); border-color:#b83a20; }
.tb-btn:hover { filter: brightness(1.12); }

.xp-body { padding: 12px; }

.loadbar {
  height: 8px; background:#d4d0c0; border:1px solid #a09e90;
  border-radius: 4px; overflow: hidden; margin-bottom: 12px;
}
.loadbar-fill {
  height: 100%; width: 40%;
  background: repeating-linear-gradient(90deg,#3b8cff 0 12px,#79b0ff 12px 18px);
  border-radius: 4px;
  animation: slide 1.6s linear infinite;
}
@keyframes slide { 0%{ transform: translateX(-100%);} 100%{ transform: translateX(300%);} }

.grid-main { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 720px){ .grid-main { grid-template-columns: 1fr; } }

/* ---- Panels ---- */
.panel {
  background: var(--luna-panel);
  border: 1px solid #b8b49f;
  border-radius: 4px;
  padding: 12px;
  box-shadow: inset 0 0 0 1px #fff;
}
.panel.wide { margin-top: 12px; }
.panel-title {
  font-weight: 700; color: #003399; font-size: 14px;
  margin-bottom: 10px; border-bottom: 1px solid #cfcbb3; padding-bottom: 5px;
}
.panel-title-row { display:flex; justify-content: space-between; align-items:center;
  margin-bottom: 8px; border-bottom: 1px solid #cfcbb3; padding-bottom: 5px; }
.panel-title-row .panel-title { border:none; margin:0; padding:0; }

.field-label { display:block; font-size:12px; font-weight:600; color:#444; margin-bottom:4px; }

.xp-select {
  width: 100%; padding: 5px 6px; font-size: 13px;
  border: 1px solid #7f9db9; border-radius: 3px;
  background: #fff; margin-bottom: 12px;
  font-family: inherit;
}

.gen-btn {
  width: 100%; padding: 12px; font-size: 15px; font-weight: 700;
  color: #14300a; cursor: pointer; border-radius: 5px;
  border: 1px solid #3d7a1c;
  background: linear-gradient(180deg,#a3e05e 0%, #74c236 48%, #5aa62c 100%);
  box-shadow: inset 0 1px 0 #d0f5a0, 0 2px 4px rgba(0,0,0,.25);
  transition: transform .05s;
}
.gen-btn:hover { filter: brightness(1.06); }
.gen-btn:active { transform: translateY(2px);
  box-shadow: inset 0 2px 4px rgba(0,0,0,.3); }

.sound-row { display:flex; gap:6px; margin-top:10px; flex-wrap: wrap; }
.mini-btn {
  padding: 5px 8px; font-size: 11.5px; cursor: pointer;
  border: 1px solid #8a8a72; border-radius: 3px;
  background: linear-gradient(180deg,#fdfdf8,#dedbc9);
  font-family: inherit;
}
.mini-btn:hover { filter: brightness(.97); }
.mini-btn:active { box-shadow: inset 0 2px 3px rgba(0,0,0,.25); }

.curve-box {
  margin-top: 10px; padding: 8px; font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px; background: #1b1b28; color: #7fffd4;
  border-radius: 4px; line-height: 1.7; overflow-x: auto;
}
.curve-box div:last-child { color: #ff9e9e; }

.genuine-box { margin-top: 12px; }
.genuine-bar {
  margin-top: 8px; height: 20px; background:#d4d0c0;
  border:1px solid #999; border-radius:3px; overflow:hidden;
}
.genuine-fill {
  height:100%; width:0; color:#fff; font-size:11px; font-weight:700;
  text-align:center; line-height:20px;
  background: repeating-linear-gradient(90deg,#3b8cff 0 14px,#79b0ff 14px 22px);
  animation: fillgen 2.4s ease forwards;
}
@keyframes fillgen { from { width:0; } to { width:88%; } }

/* ---- Output ---- */
.out-label { font-size:12px; font-weight:600; color:#555; margin:8px 0 4px; }
.keybox, .idbox {
  display:flex; align-items:center; justify-content:space-between; gap:8px;
  background:#fff; border:2px inset #b8b49f; border-radius:3px;
  padding: 8px 10px;
}
.keytext {
  font-family:'IBM Plex Mono', monospace; font-size:16px; font-weight:600;
  letter-spacing:.5px; color:#0a2f66; word-break: break-all;
}
.copy-btn {
  padding:4px 10px; font-size:11px; cursor:pointer; flex-shrink:0;
  border:1px solid #7f9db9; border-radius:3px;
  background:linear-gradient(180deg,#fdfdf8,#dedbc9); font-family:inherit;
}
.copy-btn:active { box-shadow: inset 0 2px 3px rgba(0,0,0,.25); }

.pid-line { font-family:'IBM Plex Mono', monospace; font-size:15px; font-weight:600; word-break:break-all; }
.pid-seg { padding:1px 2px; border-radius:2px; cursor:help; }
.pid-dash { color:#888; }
.seg-fam { background:#dbe9ff; color:#0a3e9e; }
.seg-chan { background:#ffe6cc; color:#a04d00; }
.seg-seq { background:#e0f5d4; color:#2f6a12; }
.seg-check { background:#ffd6d6; color:#a01414; }
.seg-idx { background:#e8dcff; color:#5a2ea6; }
.seg-rand { background:#f0f0f0; color:#666; }

.badges { display:flex; gap:6px; flex-wrap:wrap; margin-top:12px; }
.badge { font-size:11px; padding:3px 8px; border-radius:10px; font-weight:600; }
.badge.ok { background:#d6f5c4; color:#2c6510; border:1px solid #8ac263; }
.badge.info { background:#dbe9ff; color:#0a3e9e; border:1px solid #7fa8e6; }
.badge.err { background:#ffd6d6; color:#a01414; border:1px solid #e08a8a; }

.empty-out { color:#777; font-size:13px; padding:16px 4px; }

/* ---- Tabs ---- */
.tabs { display:flex; gap:2px; margin-bottom:-1px; }
.tab {
  padding:6px 14px; font-size:12.5px; cursor:pointer;
  border:1px solid #b8b49f; border-bottom:none;
  border-radius:5px 5px 0 0; font-family:inherit;
  background:linear-gradient(180deg,#eceada,#d8d4c2);
}
.tab.active {
  background:#fff; font-weight:700; color:#003399;
  position:relative; z-index:2;
}
.tab-content {
  border:1px solid #b8b49f; border-radius:0 4px 4px 4px;
  background:#fff; padding:14px; min-height:120px;
}
.hint { color:#888; font-size:13px; }

.real-badge {
  font-size:11.5px; font-weight:700; color:#0a7a4a;
  background:#e0f7ec; border:1px solid #7fd0a8; border-radius:4px;
  padding:6px 10px; margin-bottom:10px; font-family:'IBM Plex Mono', monospace;
  word-break:break-all;
}
.theme-98 .real-badge { border-radius:0; border:2px inset #fff; background:#c0c0c0; color:#000080; }
.math-list { display:flex; flex-direction:column; gap:8px; }
.math-step {
  display:flex; gap:10px; align-items:flex-start;
  padding:6px; background:#f7f6ef; border-radius:4px;
  border-left:3px solid #3b8cff;
  animation: fadeup .4s ease both;
}
@keyframes fadeup { from { opacity:0; transform: translateY(8px);} to { opacity:1; transform:none; } }
.math-num {
  width:22px; height:22px; flex-shrink:0; border-radius:50%;
  background:#3b8cff; color:#fff; font-weight:700; font-size:12px;
  display:flex; align-items:center; justify-content:center;
}
.math-label { font-weight:600; font-size:12.5px; color:#333; }
.math-val { font-family:'IBM Plex Mono', monospace; font-size:11px; color:#0a7a4a; word-break:break-all; }

/* ---- Bit field ---- */
.bf-bar { display:flex; height:44px; border-radius:5px; overflow:hidden; border:1px solid #999; }
.bf-seg {
  display:flex; align-items:center; justify-content:center; color:#fff;
  font-size:10px; font-weight:700; min-width:24px;
  animation: bfpop .5s ease both;
}
@keyframes bfpop { from { transform: scaleX(.2); opacity:0; } to { transform:none; opacity:1; } }
.bf-seg-label { text-shadow:0 1px 1px rgba(0,0,0,.4); }
.bf-up { background:#e0554a; }
.bf-serial { background:#4a86d6; }
.bf-chan { background:#e08a2c; }
.bf-hash { background:#5eab30; }
.bf-sig { background:#7a4fd0; }
.bf-auth { background:#c94a9e; }
.bf-legend { display:flex; flex-wrap:wrap; gap:12px; margin-top:12px; }
.bf-legend-item { display:flex; align-items:center; gap:5px; font-size:12px; color:#444; }
.bf-swatch { width:14px; height:14px; border-radius:3px; display:inline-block; }
.bf-total { margin-top:10px; font-size:12px; color:#666; font-style:italic; }

.how-body { font-size:13.5px; line-height:1.55; color:#333; }
.how-p { margin:0 0 10px; }
.how-eq {
  font-family:'IBM Plex Mono', monospace; font-size:13px;
  background:#1b1b28; color:#7fffd4; padding:10px; border-radius:4px;
  margin:0 0 10px; overflow-x:auto;
}

/* ---- History ---- */
.hist-list { display:flex; flex-direction:column; gap:4px; max-height:180px; overflow-y:auto; }
.hist-item {
  display:flex; justify-content:space-between; gap:8px; padding:6px 8px;
  background:#f7f6ef; border:1px solid #ddd9c4; border-radius:3px;
  cursor:pointer; font-size:12px;
}
.hist-item:hover { background:#eef4ff; }
.hist-key { font-family:'IBM Plex Mono', monospace; font-weight:600; color:#0a2f66; word-break:break-all; }
.hist-ed { color:#888; font-size:11px; white-space:nowrap; }

/* ---- Footer ---- */
.footer { margin-top:16px; padding-top:12px; border-top:1px solid #cfcbb3;
  display:flex; justify-content:space-between; align-items:flex-end; gap:12px; flex-wrap:wrap; }
.disclaimer { font-size:10.5px; color:#777; line-height:1.5; max-width:640px; }
.remix-link {
  font-size:12px; font-weight:700; color:#0a3e9e; text-decoration:none;
  padding:5px 12px; border:1px solid #7fa8e6; border-radius:4px;
  background:linear-gradient(180deg,#eef4ff,#d3e2ff); white-space:nowrap;
}
.remix-link:hover { filter:brightness(.96); }

/* ---- Balloon ---- */
.xp-balloon {
  position:fixed; bottom:20px; right:20px; z-index:100;
  background:#ffffe1; border:1px solid #b0b085; border-radius:6px;
  padding:10px 14px; max-width:260px; box-shadow:0 4px 16px rgba(0,0,0,.3);
  animation: balloonin .3s ease;
}
@keyframes balloonin { from { transform: translateY(20px); opacity:0; } to { transform:none; opacity:1; } }
.xp-balloon-title { font-weight:700; font-size:12px; color:#333; margin-bottom:3px; }
.xp-balloon-body { font-size:12px; color:#444; }

/* ---- Win98 theme ---- */
.theme-98 { background: #008080; }
.theme-98 .xp-window { border-radius:0; border:2px solid #dfdfdf; box-shadow: 2px 2px 0 #000; }
.theme-98 .titlebar { background: linear-gradient(90deg,#000080,#1084d0); border-radius:0; }
.theme-98 .title-text { text-shadow:none; }
.theme-98 .tb-btn, .theme-98 .tb-btn.close {
  background:#c0c0c0; color:#000; border:2px outset #fff; border-radius:0; }
.theme-98 .panel, .theme-98 .xp-body { background:#c0c0c0; }
.theme-98 .xp-body { }
.theme-98 .panel { border:2px inset #fff; border-radius:0; box-shadow:none; }
.theme-98 .gen-btn { background:#c0c0c0; color:#000; border:2px outset #fff; border-radius:0;
  box-shadow:none; }
.theme-98 .gen-btn:active { border-style:inset; }
.theme-98 .panel-title, .theme-98 .keytext, .theme-98 .pid-line { color:#000080; }
.theme-98 .loadbar-fill { background: repeating-linear-gradient(90deg,#000080 0 12px,#1084d0 12px 18px); }