* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: oklch(0.2 0.005 100);
  --glass: oklch(0.24 0.008 100 / 0.82);
  --glass-strong: oklch(0.21 0.008 100 / 0.94);
  --glass-border: oklch(1 0 0 / 0.1);
  --glass-hover: oklch(0.28 0.008 100 / 0.82);
  --raised: oklch(1 0 0 / 0.06);
  --raised-hover: oklch(1 0 0 / 0.1);
  --raised-subtle: oklch(1 0 0 / 0.04);
  --hairline: oklch(1 0 0 / 0.08);
  --hairline-strong: oklch(1 0 0 / 0.2);
  --text: oklch(0.96 0.005 90);
  --muted: oklch(0.76 0.012 90);
  --accent: oklch(0.66 0.13 40);
  --accent-hover: oklch(0.62 0.13 40);
  --accent-ink: oklch(0.2 0.03 40);
  --avatar-ink: oklch(0.28 0.03 60);
  --serif-font: ui-serif, Georgia, Cambria, 'Times New Roman', serif;
  --ok: oklch(0.75 0.15 155);
  --ok-ink: oklch(0.22 0.06 155);
  --danger: oklch(0.7 0.19 22);
  --danger-ink: oklch(0.2 0.09 22);
  --blur: blur(24px) saturate(1.3);
  --shadow-float: 0 12px 40px oklch(0 0 0 / 0.45), 0 2px 8px oklch(0 0 0 / 0.3);
  --mono-font: ui-monospace, 'SF Mono', Menlo, monospace;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  /* z scale: chrome < menu < modal < toast */
  --z-chrome: 10;
  --z-menu: 20;
  --z-modal: 40;
  --z-toast: 50;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-float);
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
svg { display: block; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  transition: border-color 0.15s ease-out;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, textarea:focus { outline: none; border-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  background: var(--raised);
  border: 1px solid var(--hairline);
  transition: background 0.15s ease-out;
}
.btn:hover { background: var(--raised-hover); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-danger {
  background: var(--danger);
  border-color: transparent;
  color: var(--danger-ink);
}
.btn-danger:hover { background: oklch(0.60 0.18 22); }

/* ---------- Home ---------- */

.home-body {
  display: grid;
  place-items: center;
  background:
    radial-gradient(640px 420px at 18% 8%, oklch(0.34 0.05 45 / 0.5), transparent 70%),
    radial-gradient(720px 520px at 85% 90%, oklch(0.3 0.01 100 / 0.6), transparent 70%),
    var(--bg);
}

.home {
  width: min(560px, calc(100vw - 40px));
  padding: 48px 0;
  text-align: center;
}

.logo {
  font-family: var(--serif-font);
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.logo span { color: var(--accent); }

.tagline {
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.5;
  margin: 10px auto 32px;
  max-width: 42ch;
  text-wrap: pretty;
}

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 56px 24px;
  border-radius: 20px;
  border-style: dashed;
  border-width: 1.5px;
  border-color: var(--hairline-strong);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s ease-out, background-color 0.15s ease-out, transform 0.15s var(--ease-out);
}
.drop:hover, .drop.over {
  border-color: var(--accent);
  background: var(--glass-hover);
  color: var(--text);
}
.drop.over { transform: scale(1.01); }
.drop.busy { pointer-events: none; border-color: var(--accent); }
.drop.busy .drop-icon { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

.drop-icon { width: 34px; height: 34px; margin-bottom: 8px; color: var(--accent); }
.drop strong { font-size: 1.0625rem; font-weight: 650; color: var(--text); }
.drop span { font-size: 0.8125rem; }

.alt-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
}
.alt-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--hairline);
  transition: color 0.15s ease-out, background-color 0.15s ease-out;
}
.alt-btn svg { width: 15px; height: 15px; }
.alt-btn:hover { color: var(--text); background: var(--raised); }
.alt-btn[aria-expanded="true"] {
  color: var(--text);
  background: var(--raised);
  border-color: var(--hairline-strong);
}

.alt-pane {
  padding: 14px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}
.alt-pane textarea {
  font-family: var(--mono-font);
  font-size: 0.75rem;
  line-height: 1.5;
  min-height: 150px;
  resize: vertical;
}

.error {
  color: var(--danger);
  font-size: 0.8125rem;
  margin-top: 14px;
  min-height: 1.25em;
}

/* ---------- Review ---------- */

.review-body { height: 100vh; overflow: hidden; }

#frame {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

/* top-left chip: back + artifact title */
.logo-chip {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: var(--z-chrome);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  color: var(--text);
  text-decoration: none;
  transition: background-color 0.15s ease-out;
}
.logo-chip:hover { background: var(--glass-strong); }
.logo-chip svg { width: 15px; height: 15px; color: var(--muted); flex-shrink: 0; }
.logo-chip:hover svg { color: var(--text); }
.chip-title {
  font-size: 0.8125rem;
  font-weight: 600;
  max-width: 36vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* floating comments panel */
.panel {
  position: fixed;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: min(350px, calc(100vw - 32px));
  z-index: var(--z-chrome);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s var(--ease-out), opacity 0.25s ease-out;
}
.panel.hidden {
  transform: translateX(calc(100% + 32px));
  opacity: 0;
  pointer-events: none;
}

.panel-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 12px 16px;
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}
.panel-title {
  font-size: 0.875rem;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
}
.count {
  font-family: var(--mono-font);
  font-size: 0.6875rem;
  color: var(--muted);
  background: var(--raised);
  border-radius: 999px;
  padding: 2px 8px;
}

.panel-actions { display: flex; gap: 2px; }
.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: background-color 0.15s ease-out, color 0.15s ease-out;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { background: var(--raised); color: var(--text); }

.export-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 12px;
  z-index: var(--z-menu);
  background: var(--glass-strong);
  border-radius: 12px;
  padding: 5px;
  min-width: 176px;
  display: flex;
  flex-direction: column;
}
.export-menu button {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.8125rem;
  text-align: left;
  transition: background-color 0.15s ease-out;
}
.export-menu button svg { width: 14px; height: 14px; color: var(--muted); }
.export-menu button:not(:has(svg)) { padding-left: 33px; }
.export-menu button:hover { background: var(--raised); }

.comments {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--hairline-strong) transparent;
}

.comment {
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
  transition: border-color 0.2s ease-out;
}
.comment.focused { border-color: var(--accent); }
.comment.has-pin { cursor: pointer; }
.comment.has-pin:hover { border-color: var(--hairline-strong); }
.comment.removing {
  overflow: hidden;
  opacity: 0;
  transform: scale(0.96);
  padding-top: 0;
  padding-bottom: 0;
  margin-bottom: 0;
  border-color: transparent;
  transition: height 0.28s var(--ease-out), opacity 0.2s ease-out, transform 0.28s var(--ease-out),
    padding 0.28s var(--ease-out), margin 0.28s var(--ease-out);
}
.comment.resolved { opacity: 0.55; }
.comment.resolved > .text { text-decoration: line-through; }

.comment .head, .reply .head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.mono {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--raised-hover);
  color: var(--avatar-ink);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
button.mono { cursor: pointer; transition: transform 0.15s var(--ease-out); }
button.mono:hover { transform: scale(1.15); }
button.mono.nopin { cursor: default; transform: none; color: var(--muted); }
.mono.sm { width: 20px; height: 20px; font-size: 0.6875rem; }

.comment .author { font-weight: 600; font-size: 0.8125rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.comment .when { font-family: var(--mono-font); color: var(--muted); font-size: 0.6875rem; letter-spacing: 0.01em; white-space: nowrap; }
.comment .text { font-size: 0.8125rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }

.reply {
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--raised-subtle);
  border-radius: 10px;
}
.reply .head { margin-bottom: 4px; }
.reply .text { font-size: 0.8125rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }

.comment .actions { display: flex; gap: 14px; margin-top: 10px; }
.comment .actions button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0;
  transition: color 0.15s ease-out;
}
.comment .actions button svg { width: 12px; height: 12px; }
.comment .actions button:hover { color: var(--text); }
.comment .actions .del:hover { color: var(--danger); }

.empty {
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.55;
  text-align: center;
  padding: 32px 18px;
}
.empty strong { color: var(--text); font-weight: 650; }
.empty p + p { margin-top: 8px; }
.empty kbd {
  font-family: var(--mono-font);
  font-size: 0.6875rem;
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 1px 5px;
}

/* collapsed-panel tab */
.panel-tab {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: var(--z-chrome);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  color: var(--text);
  transition: background-color 0.15s ease-out;
}
.panel-tab:hover { background: var(--glass-strong); }
.panel-tab svg { width: 17px; height: 17px; }

/* bottom toolbar, Figma-style */
.toolbar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-chrome);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border-radius: 20px;
}
.tool {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: background-color 0.15s ease-out, color 0.15s ease-out;
}
.tool svg { width: 17px; height: 17px; }
.tool:hover { background: var(--raised); color: var(--text); }
.tool.active { background: var(--accent); color: var(--accent-ink); }
.toolbar-divider { width: 1px; align-self: stretch; margin: 6px 4px; background: var(--hairline); }
.user-tool .mono { width: 26px; height: 26px; }

/* name modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: oklch(0 0 0 / 0.5);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  width: min(380px, calc(100vw - 40px));
  border-radius: 20px;
  padding: 28px 24px 22px;
  text-align: center;
  background: var(--glass-strong);
}
.modal-mono { width: 52px; height: 52px; font-size: 1.0625rem; margin: 0 auto 16px; }
.modal h2 { font-size: 1.0625rem; font-weight: 700; margin-bottom: 8px; }
.modal p { font-size: 0.8125rem; color: var(--muted); line-height: 1.5; margin-bottom: 18px; }
.modal input { text-align: center; margin-bottom: 12px; }
.modal .btn { width: 100%; }
.modal .row { display: flex; gap: 8px; }
.modal .row .btn { flex: 1; width: auto; }
.linkish {
  display: block;
  margin: 12px auto 0;
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.15s ease-out;
}
.linkish:hover { color: var(--text); }

/* toast */
.toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  z-index: var(--z-toast);
  background: var(--ok);
  color: var(--ok-ink);
  font-weight: 600;
  font-size: 0.8125rem;
  padding: 10px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow-float);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-out, transform 0.2s var(--ease-out);
}
.toast.error { background: var(--danger); color: var(--danger-ink); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 640px) {
  .panel { top: 12px; right: 12px; bottom: 12px; width: calc(100vw - 24px); }
  .logo-chip { top: 12px; left: 12px; }
  .panel-tab { top: 12px; right: 12px; }
  .toolbar { bottom: 12px; }
  .toast { bottom: 76px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
