:root {
  --bg: #f3efe7;
  --paper: #fffdf8;
  --ink: #1f1b16;
  --muted: #85796d;
  --line: #d8cec0;
  --accent: #d96b43;
  --accent-2: #d94f4f;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  --radius: 18px;
  --btn-h: 48px;
  --safe-bottom: max(12px, env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 860px;
  min-height: 100dvh;
  padding: 12px 12px var(--safe-bottom);
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
}

.panel {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topbar {
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  position: relative;
  z-index: 12;
  overflow: visible;
}

.topbar-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.split-action {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  gap: 0;
  z-index: 30;
}

.split-action__main {
  border-top-right-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
  padding-right: 16px;
}

.split-action__toggle {
  min-width: 42px;
  padding-inline: 12px;
  border-left: 0;
  border-top-left-radius: 0 !important;
  border-bottom-left-radius: 0 !important;
  margin-left: -1px;
  box-shadow: inset 1px 0 0 rgba(216, 206, 192, 0.9);
}

.split-action.open .split-action__main,
.split-action.open .split-action__toggle {
  border-color: #c2b4a4;
}

.split-action.open .split-action__toggle {
  background: #f8f3ec;
  color: var(--ink);
}

.split-action__menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 160px;
  padding: 8px;
  display: grid;
  gap: 6px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(216, 206, 192, 0.95);
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.14);
  z-index: 80;
}

.split-action__option {
  width: 100%;
  justify-content: flex-start;
}

.title h1,
.title p {
  margin: 0;
}

.title h1 {
  font-size: 1.05rem;
  line-height: 1.2;
}

.title p {
  color: var(--muted);
  font-size: 0.9rem;
}

.badge {
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 0.92rem;
  white-space: nowrap;
}

.icon {
  width: 22px;
  height: 22px;
  display: inline-block;
  flex: 0 0 auto;
}

.icon--sm {
  width: 18px;
  height: 18px;
}

.setup {
  padding: 14px;
  display: grid;
  gap: 14px;
}

.setup-row {
  display: grid;
  gap: 8px;
}

.setup label {
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 600;
}

.toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  font: inherit;
}

.btn, .chip {
  min-height: var(--btn-h);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 14px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:active, .chip:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.btn.accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn.danger {
  background: #fff;
  color: var(--accent-2);
  border-color: #f0c1c1;
}

.chip.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.btn.primary .icon,
.chip.active .icon,
.side-tools button.active .icon {
  filter: brightness(0) invert(1);
}

.workspace-shell {
  min-height: 0;
  position: relative;
}

.workspace {
  min-height: 0;
  display: grid;
  position: relative;
  overflow: visible;
  z-index: 1;
}

.canvas-wrap {
  position: relative;
  padding: 10px;
  display: flex;
  min-height: 0;
}

canvas {
  position: relative;
  z-index: 2;
  width: 100%;
  height: auto;
  display: block;
  background: var(--paper);
  border-radius: 18px;
  border: 1px solid #e9e1d7;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.6);
  touch-action: none;
}

.side-tools {
  position: absolute;
  left: 0;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 0;
  pointer-events: none;
}

.side-tools button {
  width: 64px;
  height: 48px;
  border-radius: 24px 0 0 24px;
  border: 1px solid var(--line);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.12);
  cursor: pointer;
  pointer-events: auto;
  transform: translateX(-44px);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.side-tools button:hover {
  transform: translateX(-52px);
  box-shadow: 0 6px 14px rgba(0,0,0,0.18);
}

.side-tools button.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.side-tools button:disabled {
  cursor: default;
  pointer-events: none;
  opacity: 0.48;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.side-tools--right {
  left: auto;
  right: 0;
}

.side-tools--right button {
  border-radius: 0 24px 24px 0;
  transform: translateX(44px);
}

.side-tools--right button:hover {
  transform: translateX(52px);
}

.side-tools button:disabled:hover {
  transform: inherit;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.fold-lines {
  position: absolute;
  inset: 10px;
  z-index: 4;
  pointer-events: none;
  border-radius: 18px;
  overflow: hidden;
}

.fold-line {
  position: absolute;
  left: 0;
  width: 100%;
  height: 34px;
  transform: translateY(-50%);
}

.fold-line::before,
.fold-line::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
}

.fold-line::before {
  top: 0;
  height: 100%;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.18) 26%,
    rgba(255, 255, 255, 0.1) 40%,
    rgba(0, 0, 0, 0.045) 58%,
    rgba(0, 0, 0, 0.065) 72%,
    rgba(0, 0, 0, 0) 100%
  );
  opacity: 0.3;
}

.fold-line::after {
  top: 50%;
  transform: translateY(-50%);
  border-top: 1.5px dashed rgba(0, 0, 0, 0.22);
}

.overlay {
  position: absolute;
  inset: 10px;
  display: none;
  place-items: center;
  border-radius: 18px;
  background: rgba(18, 15, 12, 0.66);
  color: #fff;
  text-align: center;
  padding: 24px;
  z-index: 10;
  pointer-events: none;
  overflow: hidden;
}

.overlay.show {
  display: flex;
    pointer-events: auto;
    align-content: center;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    flex-direction: column;
  pointer-events: auto;
}

.overlay-card {
  max-width: 420px;
  display: grid;
  gap: 14px;
  justify-items: center;
  transition: transform 0.3s ease;
}

.overlay-card h2,
.overlay-card p {
  margin: 0;
}

.overlay-card h2 { font-size: 1.35rem; }
.overlay-card p { color: rgba(255, 255, 255, 0.9); }

.floating-next {
  position: absolute;
  z-index: 30;
  left: 50%;
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding-inline: 18px;
  transform: translateX(-50%);
  transition: top 0.3s ease, transform 0.3s ease;
  box-shadow: 0 10px 24px rgba(0,0,0,0.15);
  color: rgba(255, 255, 255, 0.94);
  font-weight: 500;
}

.next-label {
  display: inline-flex;
  align-items: center;
}

.next-label-secondary {
  opacity: 0.88;
}

.next-arrow {
  display: inline-flex;
  align-items: center;
  margin-inline: 16px 0;
  opacity: 0.56;
  font-weight: 400;
  transform: translateY(-0.5px);
}

.footer-note {
  font-size: 0.88rem;
  color: var(--muted);
  text-align: center;
  padding-bottom: 4px;
}

.footer-note a {
    color: var(--accent);
    text-decoration: underline;
}

.hidden { display: none !important; }

@media (min-width: 720px) {
  .app {
    padding: 18px 18px var(--safe-bottom);
    gap: 16px;
  }

  .topbar, .setup { padding: 16px; }
}
