:root {
  color-scheme: dark;
  font-family: Inter, "Yu Gothic UI", "Hiragino Sans", system-ui, sans-serif;
  background: #0d1016;
  color: #f4f5f8;
  --top-height: 68px;
  --panel: #171b24;
  --panel-raised: #202631;
  --line: #353d4d;
  --muted: #aeb6c6;
  --accent: #72d7c4;
  --accent-strong: #98eddb;
  --danger: #ff7d8f;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { min-width: 320px; background: #0d1016; font-size: 16px; }
button, input, select { font: inherit; color: inherit; }
button, select, input { min-height: 44px; }
button {
  border: 1px solid var(--line); border-radius: 12px; background: #252b36; padding: 9px 13px;
  touch-action: manipulation; cursor: pointer;
}
button:active { transform: translateY(1px); background: #303744; }
button:focus-visible, input:focus-visible, select:focus-visible, canvas:focus-visible { outline: 3px solid #b3f4e7; outline-offset: 2px; }
button:disabled { opacity: .38; cursor: default; transform: none; }
select, input {
  width: 100%; border: 1px solid #444d5e; border-radius: 10px; background: #11151c; padding: 9px 11px;
}
input[type="range"] { min-height: 40px; padding: 0; accent-color: var(--accent); cursor: pointer; }

#app-shell { width: 100%; height: 100dvh; overflow: hidden; display: grid; grid-template-rows: var(--top-height) 1fr; }
.top-bar {
  position: relative; z-index: 10; display: grid; grid-template-columns: minmax(120px, 1fr) auto auto;
  align-items: center; gap: 10px; padding: max(7px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 7px max(10px, env(safe-area-inset-left));
  background: #151922; border-bottom: 1px solid #303746;
}
.project-identity { min-width: 0; height: 52px; border: 0; background: transparent; text-align: left; padding: 3px 6px; }
.project-identity:active { background: #202631; }
.project-identity span, .project-identity strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-line { color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.brand-line small { letter-spacing: 0; }
.project-identity strong { margin-top: 2px; font-size: 1rem; }
.save-state { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .75rem; white-space: nowrap; }
.save-dot { width: 7px; height: 7px; border-radius: 50%; background: #6fd6a8; box-shadow: 0 0 0 3px #6fd6a824; }
.save-dot.busy { background: #ffc96b; }
.save-dot.error { background: var(--danger); }
.top-actions { display: flex; gap: 6px; }
.icon-button { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; font-size: 1.35rem; }

#roll-stage { position: relative; min-height: 0; overflow: hidden; background: #0c0f14; }
#roll-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
.gesture-hint {
  position: absolute; top: 10px; left: 50%; translate: -50% 0; pointer-events: none;
  padding: 6px 10px; border-radius: 999px; background: #111620d9; border: 1px solid #343c4b;
  color: #cbd2df; font-size: .72rem; white-space: nowrap; opacity: .92;
}
.selection-toolbar {
  position: absolute; z-index: 5; left: max(82px, calc(env(safe-area-inset-left) + 74px)); right: 10px;
  bottom: calc(90px + env(safe-area-inset-bottom)); min-height: 46px; display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 6px 7px 6px 13px; border: 1px solid #495365; border-radius: 16px; background: #1b202bd9; backdrop-filter: blur(14px);
  box-shadow: 0 12px 28px #0008; font-size: .8rem;
}
.selection-toolbar[hidden] { display: none; }
.selection-toolbar span { margin-right: auto; }
.selection-toolbar button { min-height: 34px; padding: 5px 10px; }
.danger-button { color: #ffc4cc; border-color: #6e414c; }
.paste-toolbar { border-color: #4e8178; }

.transport {
  position: absolute; z-index: 4; left: max(9px, env(safe-area-inset-left)); right: max(9px, env(safe-area-inset-right));
  bottom: max(9px, env(safe-area-inset-bottom)); min-height: 72px; display: flex; align-items: center; gap: 7px;
  padding: 8px; border: 1px solid #3c4555; border-radius: 22px; background: #181d27e8; backdrop-filter: blur(18px);
  box-shadow: 0 16px 42px #000b;
}
.transport button { flex: 0 0 auto; }
.primary-round { width: 54px; height: 54px; padding: 0; border-radius: 50%; background: var(--accent); border-color: var(--accent); color: #08211d; font-weight: 800; }
.transport-button { min-width: 48px; height: 46px; padding: 7px 9px; }
.transport-button[aria-pressed="true"] { background: #345e57; border-color: #73cbbb; color: white; }
.speed-control { width: 74px; display: grid; gap: 2px; color: var(--muted); font-size: .65rem; }
.speed-control select { min-height: 38px; padding: 5px 7px; }
.position-label { min-width: 62px; color: #dbe0ea; font-variant-numeric: tabular-nums; font-size: .76rem; text-align: center; }
.zoom-button { min-width: 42px; font-size: 1.25rem; }

.sheet-dialog {
  width: min(100% - 20px, 520px); max-height: min(88dvh, 760px); margin: auto; padding: 0; border: 1px solid #424b5c;
  border-radius: 24px; background: #171b24; color: #f4f5f8; box-shadow: 0 30px 100px #000d;
}
.sheet-dialog::backdrop { background: #06080db8; backdrop-filter: blur(5px); }
.sheet { max-height: inherit; overflow-y: auto; padding: 18px; padding-bottom: max(20px, env(safe-area-inset-bottom)); display: grid; gap: 15px; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-header small { color: var(--accent); letter-spacing: .12em; font-size: .68rem; }
.sheet h2 { margin: 2px 0 0; font-size: 1.35rem; }
.sheet p { margin: 0; line-height: 1.55; }
.field { display: grid; gap: 6px; color: #dce1ea; font-size: .86rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card { display: grid; gap: 11px; padding: 13px; border: 1px solid #343c4b; border-radius: 16px; background: #11151c; }
.card-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.card-title span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .77rem; }
.help, .privacy-note { color: var(--muted); font-size: .78rem; }
.privacy-note { padding: 10px 12px; border-left: 3px solid #48796f; background: #101a1a; }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.accent-button { color: #08211d; background: var(--accent); border-color: var(--accent); font-weight: 700; }
.compact-dialog { width: min(100% - 20px, 420px); }
.visually-hidden { position: fixed; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 680px) {
  :root { --top-height: 72px; }
  .top-bar { grid-template-columns: minmax(100px, 1fr) auto; gap: 5px; }
  .save-state { position: absolute; left: 16px; bottom: 3px; }
  .top-actions { grid-column: 2; }
  .top-actions .icon-button { width: 40px; height: 42px; }
  .transport { gap: 5px; overflow: hidden; }
  .transport-button { min-width: 44px; padding-inline: 7px; font-size: .75rem; }
  .position-label { display: none; }
  .zoom-button { display: none; }
  .selection-toolbar { left: 78px; }
}

@media (min-width: 681px) {
  .transport { left: 50%; right: auto; width: min(760px, calc(100% - 24px)); translate: -50% 0; }
  .selection-toolbar { left: 50%; right: auto; width: min(660px, calc(100% - 120px)); translate: -50% 0; }
}

@media (max-width: 390px) {
  .transport { padding: 7px; }
  .primary-round { width: 50px; height: 50px; }
  .transport-button { min-width: 40px; padding-inline: 5px; }
  .speed-control { width: 66px; }
  .selection-toolbar { left: 8px; right: 8px; }
  .sheet-dialog { width: calc(100% - 12px); border-radius: 20px; }
  .sheet { padding: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
