:root {
  --bg: #12151a;
  --panel: #181c23;
  --panel-2: #1f242d;
  --line: #2a303b;
  --text: #e6e9ef;
  --muted: #8b93a3;
  --accent: #3ea6ff;
  --accent-2: #2b82d0;
  --good: #4cd08a;
  --bad: #ff6b6b;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font-size: 13px; }
body { display: flex; flex-direction: column; overflow: hidden; }

header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-size: 17px; font-weight: 700; letter-spacing: .2px; display: flex; align-items: baseline; gap: 8px; }
.brand .logo { width: 26px; height: 26px; align-self: center; }
.brand small { font-weight: 400; color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

button {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 7px; cursor: pointer;
}
button:hover { border-color: #3a4352; background: #262c37; }
button.primary { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 700; }
button.primary:hover { background: #63b8ff; }
button.ghost { background: transparent; }

main { flex: 1; display: flex; min-height: 0; }

#panel {
  width: 340px; flex: none; overflow-y: auto; background: var(--panel);
  border-right: 1px solid var(--line); padding-bottom: 40px;
}
.presets { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.presets-title { color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: .08em; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 5px 10px; font-size: 12px; border-radius: 999px; }

details { border-bottom: 1px solid var(--line); }
summary {
  list-style: none; cursor: pointer; padding: 11px 14px; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center; user-select: none;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: "▾"; color: var(--muted); transition: transform .15s; }
details:not([open]) summary::after { transform: rotate(-90deg); }
summary:hover { background: var(--panel-2); }
.group { padding: 4px 14px 14px; display: grid; gap: 11px; }

.ctl .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 3px; }
.ctl label { color: var(--text); cursor: default; }
.ctl .num { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.ctl input[type=number] {
  width: 66px; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 5px; padding: 3px 5px; font: inherit; text-align: right;
}
.ctl input[type=number]:focus { outline: 1px solid var(--accent); }
.ctl input[type=range] { width: 100%; accent-color: var(--accent); margin: 0; }
.ctl .hint { color: var(--muted); font-size: 11px; margin-top: 2px; }
.ctl.modified label::after { content: " •"; color: var(--accent); }

.seg { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { flex: 1; border: 0; border-radius: 0; background: var(--bg); }
.seg button.on { background: var(--accent); color: #04121f; font-weight: 700; }

#viewport { position: relative; flex: 1; min-width: 0; }
#gl { width: 100%; height: 100%; display: block; outline: none; }

.toolbar {
  position: absolute; top: 12px; left: 12px; display: flex; gap: 6px; align-items: center;
  background: rgba(24,28,35,.86); border: 1px solid var(--line); border-radius: 9px; padding: 5px;
  backdrop-filter: blur(6px);
}
.toolbar.right { left: auto; right: 12px; gap: 12px; padding: 7px 12px; color: var(--muted); }
.toolbar.right label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.toolbar.right select { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 5px; padding: 2px 4px; font: inherit; }
.toolbar button { padding: 4px 10px; background: transparent; border-color: transparent; }
.toolbar button:hover { background: var(--panel-2); }

#hud {
  position: absolute; left: 12px; bottom: 12px; min-width: 250px;
  background: rgba(24,28,35,.88); border: 1px solid var(--line); border-radius: 9px;
  padding: 10px 12px; line-height: 1.65; backdrop-filter: blur(6px);
}
#hud .k { color: var(--muted); display: inline-block; min-width: 108px; }
#hud .ok { color: var(--good); }
#hud .bad { color: var(--bad); }

#toast {
  position: absolute; right: 14px; bottom: 14px; background: var(--panel-2); border: 1px solid var(--line);
  padding: 9px 13px; border-radius: 8px; opacity: 0; transform: translateY(6px);
  transition: opacity .2s, transform .2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: none; }

@media (max-width: 820px) {
  main { flex-direction: column-reverse; }
  #panel { width: 100%; height: 45%; border-right: 0; border-top: 1px solid var(--line); }
  .brand small { display: none; }
  .toolbar.right { display: none; }
}

/* reset buttons */
summary .reset-sec { margin-left: auto; margin-right: 10px; padding: 2px 9px; font-size: 11px; border-radius: 999px; color: var(--accent); background: transparent; visibility: hidden; }
summary .reset-sec:hover { background: var(--panel); border-color: var(--accent); }
.ctl .rst { padding: 0 5px; line-height: 20px; font-size: 14px; border-radius: 5px; color: var(--accent); background: transparent; border-color: transparent; visibility: hidden; }
.ctl.modified .rst { visibility: visible; }
.ctl .rst:hover { border-color: var(--accent); }
#hud { max-height: 55%; overflow-y: auto; }

/* ===== accessibility & UX pass ===== */

/* visible keyboard focus everywhere */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.ctl input[type=range]:focus-visible { outline-offset: 4px; }
#gl:focus-visible { outline-offset: -3px; }

/* a little more readable help text */
.ctl .hint { font-size: 12px; line-height: 1.4; }

/* header menus */
.menu { position: relative; display: flex; }
.menu-list {
  position: absolute; top: calc(100% + 6px); left: 0; min-width: 230px; z-index: 40;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 4px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.menu-list.right { left: auto; right: 0; }
.menu-list[hidden] { display: none; }
.menu-list button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 6px; }
.menu-list button:hover, .menu-list button:focus-visible { background: #2b3240; }
.menu-list button[hidden] { display: none; }
.menu-list .danger { color: var(--bad); border-top: 1px solid var(--line); border-radius: 0 0 6px 6px; margin-top: 4px; }

.split > .primary:first-child { border-radius: 7px 0 0 7px; }
.split > .caret { border-radius: 0 7px 7px 0; border-left: 1px solid rgba(4,18,31,.35); padding: 7px 10px; }

/* slightly larger controls on desktop */
.ctl .rst { min-width: 26px; min-height: 26px; }
summary .reset-sec { padding: 4px 10px; }

/* touch screens and phones: 44px targets */
@media (pointer: coarse), (max-width: 820px) {
  button, .ctl input[type=number], select, summary { min-height: 44px; }
  .ctl input[type=number] { width: 78px; font-size: 16px; }
  .ctl .rst, summary .reset-sec { min-width: 44px; min-height: 44px; }
  .ctl .num { gap: 6px; }
  .chips button { min-height: 40px; padding: 6px 14px; }
  .seg button { min-height: 44px; }
  .ctl input[type=range] { height: 32px; }
  .menu-list button { min-height: 44px; }
  .toolbar button { min-height: 40px; min-width: 52px; }
  .toolbar.right label { min-height: 40px; }
}

/* phone layout: model first, controls below, details overlay collapsed */
@media (max-width: 820px) {
  header { padding: 8px 10px; }
  .actions { flex-wrap: nowrap; gap: 6px; }
  .actions button { padding: 6px 10px; }
  main { flex-direction: column-reverse; }
  #viewport { flex: 1 1 auto; min-height: 240px; }
  #panel { width: 100%; height: 46%; flex: none; border-right: 0; border-top: 1px solid var(--line); }
  .toolbar.right { display: flex; left: 12px; right: 12px; top: 64px; flex-wrap: wrap; gap: 6px 12px; padding: 4px 10px; font-size: 12px; }
  .toolbar.right label:nth-last-child(-n+2) { display: none; }   /* plate size controls stay desktop-only */
  #hud { left: 8px; right: 8px; bottom: 8px; min-width: 0; max-height: 60%; padding: 8px 10px; cursor: pointer; line-height: 1.5; }
  #hud:not(.open) > div:nth-child(n+2) { display: none; }
  #hud:not(.open) > div:first-child::after { content: "  ▴ details"; color: var(--accent); }
  #hud.open > div:first-child::after { content: "  ▾"; color: var(--accent); }
  #hud .k { min-width: 96px; }
  #toast { left: 12px; right: 12px; bottom: 64px; text-align: center; }
}

/* respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
a.brand { color: inherit; text-decoration: none; }
