:root {
      --bg: #0f172a; --panel: #1e293b; --panel-2: #334155; --text: #f8fafc;
      --muted: #94a3b8; --line: #475569; --board: #fde68a; --board-border: #92400e;
      --accent: #38bdf8; --danger: #f43f5e; --success: #22c55e;
    }

    * { box-sizing: border-box; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
    input { -webkit-user-select: auto; user-select: auto; }

    html, body { width: 100%; height: 100vh; margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, sans-serif; overflow: hidden; touch-action: none; }
    body { display: grid; grid-template-rows: auto 1fr; }

    header { background: var(--panel); border-bottom: 1px solid var(--line); padding: 0.75rem; z-index: 100; box-shadow: 0 4px 20px rgba(0,0,0,0.3); }
    .toolbar { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-bottom: 0.75rem; }

    input, select, button { font-size: 16px !important; padding: 0.4rem 0.6rem; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); color: white; }
    button { cursor: pointer; border: none; font-weight: 600; }
    button:active { transform: translateY(1px); filter: brightness(1.2); }
    .btn-primary { background: var(--accent); color: var(--bg); }
    .btn-save { background: var(--success); color: white; }
    .btn-danger { background: var(--danger); }

    .slider-container { display: flex; align-items: center; gap: 10px; font-size: 0.8rem; color: var(--muted); }
    input[type="range"] { flex-grow: 1; min-width: 120px; accent-color: var(--accent); }

    main { position: relative; overflow: hidden; background: #020617; }
    #workspace { position: absolute; inset: 0; overflow: auto; cursor: crosshair; }
    #stage { position: relative; min-width: 100%; min-height: 100%; transform-origin: top left; }

    .board {
      position: absolute; border: 2px solid var(--board-border); background: var(--board); color: #451a03;
      border-radius: 2px; display: flex; flex-direction: column; align-items: center; justify-content: center;
      font-weight: bold; text-align: center; cursor: grab; box-shadow: 2px 2px 0px rgba(0,0,0,0.2);
      touch-action: none;
    }
    .board.selected { outline: 3px solid var(--accent); outline-offset: 2px; z-index: 10; box-shadow: 0 0 15px var(--accent); }
    .board span { pointer-events: none; font-size: 0.7rem; display: block; line-height: 1.2; }
    .board .size { opacity: 0.7; font-weight: normal; font-size: 0.6rem; }

    .hud { position: absolute; bottom: 1rem; left: 1rem; right: 1rem; display: flex; justify-content: space-between; gap: 0.75rem; pointer-events: none; }
    .hud-chip { background: rgba(15, 23, 42, 0.9); padding: 0.5rem 1rem; border-radius: 8px; border: 1px solid var(--line); font-size: 0.75rem; }

    #importFile { display: none; }

.toolbar-spacer { flex: 1 1 auto; min-width: 0; }
#layoutSelector { flex: 1 1 12rem; min-width: 9rem; }
.board-entry-toolbar > input { min-width: 0; }
.input-label { flex: 2 1 clamp(8rem, 30vw, 14rem); width: auto; max-width: 18rem; }
.input-dimension { flex: 1 1 clamp(4.75rem, 14vw, 7rem); width: auto; max-width: 8rem; }
.toolbar-divider { flex: 0 0 1px; width: 1px; height: 20px; background: var(--line); margin: 0 5px; }
.slider-container > span { white-space: nowrap; }

@media (max-width: 620px) {
  header { padding: 0.6rem; }
  .toolbar { gap: 0.35rem; }
  #layoutSelector { flex: 1 1 100%; max-width: none; }
  .toolbar-spacer { display: none; }
  .board-entry-toolbar { align-items: stretch; }
  .input-label { flex: 1 1 100%; max-width: none; }
  .input-dimension { flex: 1 1 calc(50% - 0.35rem); max-width: none; }
  #addBtn { flex: 1 1 calc(50% - 0.35rem); }
  .toolbar-divider { display: none; }
  .board-entry-toolbar button:not(#addBtn) { flex: 1 1 calc(50% - 0.35rem); }
  .slider-container { gap: 0.5rem; }
  .hud { left: 0.5rem; right: 0.5rem; bottom: 0.5rem; flex-wrap: wrap; }
}

@media (max-width: 390px) {
  input, select, button { padding: 0.4rem 0.5rem; }
  .board-entry-toolbar button:not(#addBtn) { flex-basis: 100%; }
}

