:root {
  --bg: #0d1016; --panel: #151a22; --panel2: #1c222c; --line: #2a313d; --text: #e6e9ef;
  --muted: #8b94a3; --accent: #7aa2ff; --warn: #ff7a6b;
  --top: env(safe-area-inset-top, 0px); --bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; }
body { overscroll-behavior: none; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; min-height: 40px; }
button:active { background: #232a36; }
button:disabled { opacity: .4; }
button.primary { background: var(--accent); border-color: var(--accent); color: #0b1020; font-weight: 600; }
button.danger { color: var(--warn); }
button.chip { min-height: 32px; padding: 5px 10px; font-size: 13px; border-radius: 8px; }
button.icon { min-width: 40px; font-size: 26px; line-height: 1; padding: 4px 8px; background: none; border: 0; }
input[type=text], input[type=search] { width: 100%; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font-size: 16px; }
.muted { color: var(--muted); }

.screen { display: flex; flex-direction: column; min-height: 100%; padding-top: var(--top); }
.bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; min-height: 52px; }
.bar h1 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-end { display: flex; gap: 6px; }
#editor .bar { padding-left: 6px; }

.lede { margin: 0 16px 14px; color: var(--muted); font-size: 14px; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 0 16px calc(24px + var(--bottom)); }
.tile { background: none; border: 0; padding: 0; min-height: 0; text-align: left; }
.tile canvas { width: 100%; aspect-ratio: 330 / 480; display: block; border-radius: 16px; }
.tile .meta { display: block; font-size: 12px; color: var(--muted); margin-top: 5px; padding-left: 2px; }

#editor { height: 100%; min-height: 0; }
.stage { flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; }
#card { touch-action: none; display: block; }
.dock { padding: 6px 16px calc(10px + var(--bottom)); display: grid; gap: 8px; }
.row { display: flex; gap: 6px; }
.row button { flex: 1; padding-left: 4px; padding-right: 4px; font-size: 14px; }
.row.main button { min-height: 44px; font-size: 15px; }
.hint { margin: 0; text-align: center; font-size: 12px; color: var(--muted); min-height: 40px; display: grid; place-items: center; }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; z-index: 10; }
.sheet-panel { width: 100%; max-height: 72%; background: var(--panel); border-top-left-radius: 16px; border-top-right-radius: 16px;
  border-top: 1px solid var(--line); display: flex; flex-direction: column; padding-bottom: var(--bottom); }
.sheet-panel.small { padding: 16px 16px calc(16px + var(--bottom)); gap: 8px; display: grid; }
.sheet-panel h2 { font-size: 17px; margin: 0 0 4px; }
.sheet-head { display: flex; gap: 8px; align-items: center; padding: 12px 16px 8px; }
/* explicit row heights: Safari collapses aspect-ratio rows in a scrolling grid */
.picker-grid { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; display: grid; grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: calc((min(100vw, 640px) - 50px) / 4); gap: 6px; padding: 4px 16px 16px; }
.pick { background: var(--panel2); border-radius: 10px; padding: 6px; min-height: 0; display: grid; place-items: center; }
.pick img { max-width: 100%; max-height: 100%; object-fit: contain; pointer-events: none; }
.picker-note { grid-column: 1 / -1; color: var(--muted); font-size: 13px; margin: 4px 0 8px; }
.error { color: var(--warn); font-size: 13px; margin: 0; }

.toast { position: fixed; left: 50%; bottom: calc(110px + var(--bottom)); transform: translateX(-50%); max-width: calc(100% - 32px);
  background: #24304a; border: 1px solid var(--accent); padding: 8px 14px; border-radius: 10px; font-size: 14px;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20; }
.toast.show { opacity: 1; }
