:root {
  color-scheme: light;
  --paper: #f4f2eb;
  --surface: #ffffff;
  --ink: #18201f;
  --muted: #68706d;
  --line: #c8ccc7;
  --line-strong: #18201f;
  --coral: #d4513f;
  --cyan: #58bfd0;
  --yellow: #f1c54b;
  --green: #2c8a70;
  --danger: #b6382d;
  --app-h: 62px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; min-height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, "Noto Sans SC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}
button, input, select { color: inherit; font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .38; }
:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

.app-bar {
  position: relative;
  z-index: 10;
  height: var(--app-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 18px;
  border-bottom: 1px solid var(--line-strong);
  background: var(--surface);
}
.brand { display: inline-flex; align-items: center; gap: 9px; color: inherit; font-size: 13px; font-weight: 900; text-decoration: none; }
.brand img { width: 36px; height: 36px; border-radius: 7px; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; width: 190px; height: 38px; padding: 3px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--paper); }
.mode-switch button { border: 0; border-radius: 4px; background: transparent; font-size: 12px; font-weight: 800; }
.mode-switch button.is-active { background: var(--ink); color: #fff; }
.top-actions { justify-self: end; display: flex; align-items: center; gap: 7px; }
.icon-button, .command-button { height: 36px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); font-size: 12px; font-weight: 800; }
.icon-button { width: 36px; padding: 0; font-size: 20px; line-height: 1; }
.command-button { padding: 0 13px; }
.command-button.primary { background: var(--coral); color: #fff; }

.workspace {
  height: calc(100vh - var(--app-h));
  height: calc(100dvh - var(--app-h));
  display: grid;
  grid-template-columns: 260px minmax(440px, 1fr) 270px;
  min-width: 0;
}
.settings-panel, .arrow-panel { min-height: 0; overflow-y: auto; background: var(--surface); }
.settings-panel { border-right: 1px solid var(--line-strong); }
.arrow-panel { border-left: 1px solid var(--line-strong); }
.settings-panel section, .arrow-panel section { padding: 18px; border-bottom: 1px solid var(--line); }
.section-title { min-height: 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.section-title h2 { margin: 0; font-size: 13px; line-height: 1.2; }
.section-title span, .section-title output { color: var(--muted); font-size: 11px; }
.section-title button { border: 0; background: transparent; color: var(--danger); font-size: 11px; font-weight: 800; }

.field-row { display: grid; grid-template-columns: .8fr 1.2fr; gap: 9px; }
.field { min-width: 0; display: grid; gap: 6px; margin-bottom: 11px; }
.field.wide { width: 100%; }
.field span, .slider-field span { color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.field input, .field select {
  width: 100%;
  height: 36px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  padding: 0 9px;
  font-size: 12px;
}
.slider-field { display: grid; grid-template-columns: 48px 1fr; align-items: center; gap: 8px; margin: 3px 0 14px; }
.slider-field input { width: 100%; accent-color: var(--green); }
.generate-button, .danger-button, .accent-button, .play-controls button, .result-overlay button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 900;
}
.generate-button { width: 100%; background: var(--yellow); }
.generate-button span { margin-right: 5px; font-size: 15px; }
.danger-button { width: 100%; background: transparent; color: var(--danger); }
.toggle-field { min-height: 38px; display: flex; align-items: center; gap: 9px; font-size: 12px; font-weight: 700; }
.toggle-field input { width: 17px; height: 17px; accent-color: var(--yellow); }

.board-stage { min-width: 0; min-height: 0; display: grid; grid-template-rows: 46px minmax(0, 1fr) 52px; background: var(--paper); }
.stage-status { display: flex; align-items: center; justify-content: space-between; padding: 0 16px; border-bottom: 1px solid var(--line); font-size: 11px; }
.stage-status div { display: flex; align-items: center; gap: 7px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.status-dot.invalid { background: var(--danger); }
.stage-status > span { color: var(--muted); }
.canvas-frame { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#level-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
body[data-mode="play"] #level-canvas { cursor: pointer; }
.canvas-frame.is-wrong { animation: wrong-shake 220ms ease-in-out; }
.edit-status, .play-controls { min-width: 0; border-top: 1px solid var(--line-strong); background: var(--surface); }
.edit-status { display: flex; align-items: center; justify-content: space-between; padding: 0 16px; color: var(--muted); font-size: 11px; }
.play-controls { display: grid; grid-template-columns: auto minmax(130px, 1fr) auto auto; align-items: center; gap: 12px; padding: 0 14px; }
.lives { min-width: 68px; color: var(--coral); font-size: 19px; letter-spacing: 2px; }
.play-progress { display: grid; grid-template-columns: auto minmax(80px, 1fr); align-items: center; gap: 9px; font-size: 11px; }
.play-progress i { height: 6px; overflow: hidden; border-radius: 3px; background: var(--line); }
.play-progress b { display: block; width: 0; height: 100%; background: var(--green); transition: width 180ms ease; }
.play-controls button { min-width: 70px; background: var(--surface); }
.play-controls .accent-button { background: var(--cyan); }
.result-overlay { position: absolute; inset: 0; z-index: 3; display: grid; place-content: center; justify-items: center; gap: 11px; background: rgba(244, 242, 235, .9); }
.result-overlay[hidden] { display: none; }
.result-overlay strong { font-size: 42px; }
.result-overlay span { color: var(--muted); font-size: 12px; }
.result-overlay button { padding: 0 18px; background: var(--yellow); }

.validation-panel p { min-height: 42px; margin: 0 0 13px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.validation-panel p.error { color: var(--danger); }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); }
.metric-grid div { min-width: 0; display: grid; justify-items: center; gap: 3px; padding: 10px 3px; border-right: 1px solid var(--line); }
.metric-grid div:last-child { border-right: 0; }
.metric-grid strong { font-size: 18px; }
.metric-grid span { color: var(--muted); font-size: 9px; }
.arrow-list-section { min-height: 250px; }
.arrow-list { display: grid; gap: 5px; }
.arrow-row { width: 100%; min-height: 38px; display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 9px; border: 1px solid transparent; border-radius: 5px; background: transparent; padding: 0 8px; text-align: left; }
.arrow-row:hover { background: var(--paper); }
.arrow-row.is-selected { border-color: var(--line-strong); background: var(--paper); }
.arrow-row i { width: 10px; height: 10px; border-radius: 50%; background: var(--arrow-color); }
.arrow-row strong { min-width: 0; font-size: 11px; }
.arrow-row span { color: var(--muted); font-size: 10px; }
.empty-list { padding: 24px 6px; color: var(--muted); text-align: center; font-size: 11px; }

.toast { position: fixed; z-index: 30; left: 50%; bottom: 22px; max-width: min(460px, calc(100vw - 32px)); transform: translate(-50%, 18px); border: 1px solid var(--line-strong); border-radius: 6px; background: var(--ink); color: #fff; padding: 10px 14px; font-size: 12px; opacity: 0; pointer-events: none; transition: opacity 160ms ease, transform 160ms ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@keyframes wrong-shake { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-7px); } 70% { transform: translateX(7px); } }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 230px minmax(400px, 1fr); }
  .arrow-panel { display: none; }
}
@media (max-width: 760px) {
  body { overflow: auto; }
  .app-bar { height: auto; min-height: 112px; grid-template-columns: 1fr auto; grid-template-rows: 54px 48px; padding: 0 12px; }
  .mode-switch { grid-column: 1; grid-row: 2; width: 176px; }
  .top-actions { grid-column: 2; grid-row: 1 / span 2; display: grid; grid-template-columns: repeat(2, 40px); }
  .command-button { width: 40px; overflow: hidden; padding: 0 5px; font-size: 10px; }
  .workspace { height: auto; min-height: calc(100dvh - 112px); grid-template-columns: 1fr; grid-template-rows: auto minmax(560px, 72dvh) auto; }
  .settings-panel { display: grid; grid-template-columns: 1fr 1fr; border-right: 0; border-bottom: 1px solid var(--line-strong); }
  .settings-panel section { padding: 13px; border-right: 1px solid var(--line); }
  .settings-panel section:first-child .field-row:last-child { grid-template-columns: 1fr; }
  .settings-panel .selection-settings { display: block; grid-column: 1 / -1; border-right: 0; }
  .arrow-panel { display: block; border-left: 0; border-top: 1px solid var(--line-strong); }
  .arrow-list-section { display: none; }
  .board-stage { min-height: 560px; }
  .play-controls { grid-template-columns: 1fr auto auto; gap: 7px; }
  .play-progress { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
