:root {
  color-scheme: light;
  --bg: #f6f3ec;
  --paper: #fffdf8;
  --ink: #23262d;
  --muted: #6a6f7a;
  --line: #dcd6c8;
  --accent: #2b5fd9;
  --danger: #c2372b;
  --radius: 12px;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button {
  font: inherit; min-height: 44px; padding: .55rem 1rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink); cursor: pointer;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.big { width: 100%; min-height: 54px; font-size: 1.05rem; }
button.ghost { background: transparent; border-color: transparent; color: var(--accent); }
button.danger { color: var(--danger); }
input, select {
  font: inherit; font-size: 16px; min-height: 44px; width: 100%; padding: .45rem .6rem;
  border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink);
}
input[type=color] { padding: 2px; width: 44px; min-width: 44px; height: 44px; }
input[type=checkbox] { width: 22px; min-height: 22px; height: 22px; margin: 0; }
label { display: grid; gap: .2rem; font-size: .85rem; color: var(--muted); font-weight: 600; }
label.check { display: flex; align-items: center; gap: .6rem; color: var(--ink); font-size: 1rem; font-weight: 500; margin-top: .6rem; }
.hint { color: var(--muted); font-size: .85rem; margin: .3rem 0 0; }
.error { color: var(--danger); font-weight: 600; min-height: 1.2em; margin: .4rem 0; }

/* views */
.view { min-height: 100dvh; }
.bar {
  display: flex; align-items: center; gap: .4rem; padding: .4rem .6rem;
  padding-top: max(.4rem, env(safe-area-inset-top));
  background: var(--paper); border-bottom: 1px solid var(--line);
}
.bar h1 { font-size: 1.1rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { font-size: 1.6rem; padding: 0 .6rem; line-height: 1; }

/* home */
#home { display: grid; place-items: center; padding: max(1.5rem, env(safe-area-inset-top)) 1rem max(1.5rem, env(safe-area-inset-bottom)); }
.home-wrap { width: min(30rem, 100%); }
.home-mark { width: 72px; height: 72px; color: var(--ink); }
#home h1 { font-size: clamp(1.8rem, 7vw, 2.4rem); margin: .4rem 0 .3rem; letter-spacing: -.01em; }
.lede { color: var(--muted); margin: 0 0 1.4rem; }
#recent h2 { font-size: 1rem; margin: 1.6rem 0 .5rem; }
#recent-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
#recent-list a {
  display: flex; justify-content: space-between; gap: 1rem; padding: .8rem 1rem; border-radius: var(--radius);
  background: var(--paper); border: 1px solid var(--line); color: var(--ink); text-decoration: none;
}
#recent-list small { color: var(--muted); white-space: nowrap; }
.install-row { margin-top: 1.6rem; display: grid; justify-items: start; gap: .3rem; }
.install-row p { margin: 0; color: var(--muted); font-size: .85rem; }
dialog { max-width: min(28rem, 90vw); border-radius: var(--radius); border: 1px solid var(--line); }

/* setup */
#setup form { width: min(40rem, 100%); margin: 0 auto; padding: 1rem 1rem max(2rem, env(safe-area-inset-bottom)); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); margin: 0 0 1rem; padding: .8rem 1rem 1rem; }
legend { font-weight: 700; padding: 0 .3rem; }
.pair { display: grid; grid-template-columns: 1fr auto 1fr; gap: .5rem; align-items: end; }
.times { padding-bottom: .7rem; color: var(--muted); }
.course { display: grid; grid-template-columns: 44px 1fr 5.5rem; gap: .5rem; align-items: end; margin-bottom: .7rem; }
.course:last-child { margin-bottom: 0; }
.custom-group { margin-top: .8rem; }
.custom-group h3 { font-size: .95rem; margin: .4rem 0; display: flex; align-items: center; gap: .4rem; }
.custom-row { display: grid; grid-template-columns: 1fr 4.6rem 4.6rem; gap: .4rem; margin-bottom: .4rem; }
.custom-row input { min-height: 40px; }
.door { display: grid; grid-template-columns: 1.35fr 1fr 1fr 44px; gap: .4rem; align-items: end; margin-bottom: .6rem; }
.door button { padding: 0; }
.dot { width: 14px; height: 14px; border-radius: 4px; display: inline-block; flex: none; }

/* plan editor */
#plan { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
#save-status { font-size: .8rem; color: var(--muted); white-space: nowrap; }
#save-status.bad { color: var(--danger); font-weight: 600; }
.toolbar { display: flex; gap: .4rem; padding: .45rem .6rem; overflow-x: auto; background: var(--paper); }
.toolbar button { flex: 1 0 auto; min-height: 40px; padding: .4rem .7rem; font-size: .92rem; }
.legend { display: flex; gap: .4rem; padding: .35rem .6rem .45rem; overflow-x: auto; background: var(--paper); border-bottom: 1px solid var(--line); }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .55rem; border-radius: 999px; background: #f0ece2; font-size: .82rem; white-space: nowrap; }
.chip.warn { background: #fbe3df; color: var(--danger); font-weight: 600; }
#stage { position: relative; flex: 1; min-height: 0; }
#floor { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; display: block; }
#gesture-hint {
  position: absolute; left: .6rem; right: .6rem; top: .4rem; margin: 0;
  text-align: center; font-size: .75rem; color: var(--muted); pointer-events: none;
}
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  background: var(--paper); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
  box-shadow: 0 -6px 24px #0002; padding: .5rem 1rem max(1rem, env(safe-area-inset-bottom));
  max-width: 34rem; margin: 0 auto;
}
.sheet-head { display: flex; align-items: center; gap: .5rem; }
.sheet-head strong { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { display: grid; gap: .5rem; }
.sheet-body .pair input, .sheet-body > label input { min-height: 40px; }
.sheet-actions { display: flex; gap: .5rem; }
.sheet-actions button { flex: 1; }
#toast {
  position: absolute; left: 50%; top: 7.5rem; transform: translateX(-50%); z-index: 6;
  background: var(--ink); color: #fff; padding: .55rem 1rem; border-radius: 999px; font-size: .9rem; max-width: 90vw; text-align: center;
}

/* svg */
.grid-minor { stroke: #e6e1d5; stroke-width: 1; }
.grid-major { stroke: #d2cbbb; stroke-width: 1; }
.room { fill: #fffefb; }
.wall { fill: none; stroke: #2e3138; stroke-width: 4; }
.door-gap { stroke: #fffefb; stroke-width: 6; }
.door-swing { fill: none; stroke: #8a8f99; stroke-width: 1; stroke-dasharray: 3 3; }
.door-label { fill: #6a6f7a; font-weight: 600; }
.item rect.body { stroke: #0003; stroke-width: 1; }
.item.obstacle rect.body { fill: #b9b4aa; stroke: #6e695f; }
.item text { pointer-events: none; font-weight: 700; dominant-baseline: central; text-anchor: middle; }
.item.bad rect.body { stroke: var(--danger); stroke-width: 3; }
.item.selected rect.body { stroke: var(--accent); stroke-width: 3; }
.item.bad.selected rect.body { stroke: var(--danger); stroke-dasharray: 6 3; }
.item.dragging rect.body { filter: drop-shadow(0 3px 4px #0004); }
.scale-label { fill: #6a6f7a; font-size: 11px; font-weight: 600; }
.scale-bar { stroke: #6a6f7a; stroke-width: 2; }
* { -webkit-touch-callout: none; }
input { -webkit-touch-callout: default; }
