/* drawkeyi — crisp minimalist white workspace aligned strictly to the sheet width. */
:root {
  --bg: #F6F6F7;
  --paper: #FFFFFF;
  --ink: #2C2C2E;
  --ink-muted: #8E8E93;
  --border-sheet: rgba(28, 28, 30, 0.085);
  --border-ui: rgba(28, 28, 30, 0.12);
  --border-ui-hover: rgba(28, 28, 30, 0.32);
  --dot-alone: #D6A15C;
  --dot-together: #58A569;
  --dot-offline: #C7C7CC;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html,
body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  touch-action: none;
}

.app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg);
  padding-top: max(4px, env(safe-area-inset-top));
  padding-right: max(6px, env(safe-area-inset-right));
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  padding-left: max(6px, env(safe-area-inset-left));
}

/* Header synced to sheet width (baseW) with focus mode while drawing */
.topbar {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  padding: 2px 0 6px;
  z-index: 10;
  opacity: 1;
  transition: opacity 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

.app.is-focus-mode .topbar {
  opacity: 0.15;
  pointer-events: none;
  transition: opacity 0.24s ease-out;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 480;
  color: var(--ink-muted);
  letter-spacing: -0.01em;
  flex-shrink: 0;
  transition: color 0.3s ease;
}

.status-dot {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--dot-alone);
  transition: background-color 0.28s ease, box-shadow 0.28s ease;
}

.status-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--dot-together);
  opacity: 0;
  transform: scale(1);
  pointer-events: none;
}

.status-dot.is-rippling::after {
  animation: dotRipple 0.9s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.status-pill.is-alone .status-dot {
  background: var(--dot-alone);
  animation: softPulse 2.6s ease-in-out infinite;
}

.status-pill.is-together {
  color: var(--ink);
}

.status-pill.is-together .status-dot {
  background: var(--dot-together);
  box-shadow: 0 0 0 3px rgba(88, 165, 105, 0.16);
  animation: none;
}

.status-pill.is-offline .status-dot {
  background: var(--dot-offline);
  animation: softPulse 1.3s ease-in-out infinite;
}

/* Typographic slot for smooth vertical crossfade on status changes */
.status-slot {
  position: relative;
  display: inline-grid;
  align-items: center;
  height: 19px;
  overflow: hidden;
}

.status-text {
  grid-area: 1 / 1;
  white-space: nowrap;
  line-height: 19px;
  will-change: transform, opacity;
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.26s ease;
}

.status-text.is-entering {
  opacity: 0;
  transform: translateY(72%);
}

.status-text.is-current {
  opacity: 1;
  transform: translateY(0);
}

.status-text.is-leaving {
  opacity: 0;
  transform: translateY(-72%);
}

.top-actions {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  flex-shrink: 0;
}

.lang-link {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-muted);
  text-decoration: none;
  padding: 5px 2px;
  white-space: nowrap;
  transition: color 0.15s ease;
}

.lang-link:hover {
  color: var(--ink);
}

/* Share button collapses smoothly into a 30x30 circle once a second user joins */
.minimal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 0 11px;
  background: #FFFFFF;
  color: var(--ink);
  border: 1px solid var(--border-ui);
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 520;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition:
    padding 0.42s cubic-bezier(0.22, 1, 0.36, 1),
    border-color 0.22s ease,
    color 0.22s ease,
    background-color 0.22s ease,
    transform 0.14s ease;
}

.minimal-btn:hover {
  border-color: var(--border-ui-hover);
}

.minimal-btn:active {
  transform: scale(0.95);
}

.minimal-btn.is-compact {
  /* 1px border + 7px padding + 14px icon + 7px padding + 1px border = exact 30x30 circle */
  padding: 0 7px;
  border-color: rgba(28, 28, 30, 0.12);
  color: var(--ink-muted);
}

.minimal-btn.is-compact:hover {
  border-color: var(--border-ui-hover);
  color: var(--ink);
}

.minimal-btn.is-copied {
  border-color: rgba(88, 165, 105, 0.55);
  color: #367B47;
  background: rgba(88, 165, 105, 0.06);
}

.minimal-btn-dark {
  height: 38px;
  padding: 0 20px;
  background: var(--ink);
  color: #FFFFFF;
  border-color: var(--ink);
  font-size: 13.5px;
}

.minimal-btn-dark:hover {
  background: #1C1C1E;
  border-color: #1C1C1E;
}

.copy-icon-slot {
  position: relative;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.btn-icon {
  position: absolute;
  inset: 0;
  width: 14px;
  height: 14px;
  transition: opacity 0.22s ease, transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

.icon-link {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.icon-check {
  opacity: 0;
  transform: scale(0.65);
}

.icon-check .check-path {
  stroke-dasharray: 20;
  stroke-dashoffset: 20;
  transition: stroke-dashoffset 0.28s cubic-bezier(0.22, 1, 0.36, 1) 0.06s;
}

.minimal-btn.is-copied .icon-link {
  opacity: 0;
  transform: scale(0.6) rotate(-18deg);
}

.minimal-btn.is-copied .icon-check {
  opacity: 1;
  transform: scale(1);
}

.minimal-btn.is-copied .icon-check .check-path {
  stroke-dashoffset: 0;
}

/* Label collapses cleanly in .is-compact while preventing layout shifts when copied */
.copy-label-slot {
  display: inline-grid;
  align-items: center;
  justify-items: center;
  height: 18px;
  max-width: 110px;
  margin-left: 5px;
  opacity: 1;
  overflow: hidden;
  transition:
    max-width 0.42s cubic-bezier(0.22, 1, 0.36, 1),
    margin-left 0.42s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.24s ease;
}

.minimal-btn.is-compact .copy-label-slot {
  max-width: 0;
  margin-left: 0;
  opacity: 0;
}

.copy-label {
  grid-area: 1 / 1;
  line-height: 18px;
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease;
}

.label-default {
  opacity: 1;
  transform: translateY(0);
}

.label-copied {
  opacity: 0;
  transform: translateY(72%);
}

.minimal-btn.is-copied .label-default {
  opacity: 0;
  transform: translateY(-72%);
}

.minimal-btn.is-copied .label-copied {
  opacity: 1;
  transform: translateY(0);
}

/* Main canvas stage */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sheet-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.sheet-frame {
  position: relative;
  background: transparent;
  transform-origin: center center;
  will-change: transform;
  cursor: crosshair;
  touch-action: none;
  overflow: visible;
}

.sheet-frame.is-panning {
  cursor: grab;
}

.sheet-frame.is-panning:active {
  cursor: grabbing;
}

.sheet-back-svg,
.sheet-front-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.sheet-back-svg {
  z-index: 0;
}

.sheet-clip {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--paper);
  overflow: hidden;
  pointer-events: none;
}

.sheet-front-svg {
  z-index: 6;
}

.sheet-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  transition: opacity 0.35s linear;
}

#static-canvas {
  z-index: 1;
}

#live-canvas {
  z-index: 2;
  mix-blend-mode: multiply;
}

/* Ultra-fine procedural paper grain:
   imperceptible at 100% zoom, softly reveals paper tooth when zoomed in. */
.paper-grain {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  opacity: 0.018;
  transition: opacity 0.25s ease;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23p)'/%3E%3C/svg%3E");
  background-size: 160px 160px;
}

/* Fine pencil onboarding prompt centered on an empty sheet */
.empty-hint {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: none;
  color: rgba(54, 54, 58, 0.32);
  opacity: 1;
  transform: translateY(0) scale(1);
  transition:
    opacity 0.4s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.empty-hint.is-hidden {
  opacity: 0;
  transform: translateY(-3px) scale(0.97);
}

.empty-hint-svg {
  width: min(228px, 64%);
  height: auto;
  display: block;
  overflow: visible;
  transform: rotate(-2deg);
}

.empty-hint-zh {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  transform: rotate(-1.4deg);
}

.empty-hint-zh-text {
  font-family: "Kaiti SC", "STKaiti", "BiauKai", "KaiTi", "PingFang SC", cursive, serif;
  font-size: clamp(20px, 5.4vw, 25px);
  font-weight: 300;
  letter-spacing: 0.14em;
  line-height: 1.25;
  text-align: center;
}

.hint-underline-svg {
  width: min(150px, 44vw);
  height: auto;
  display: block;
  opacity: 0.72;
}

/* Subtle corner prompt with arrow pointing to the curled page corner */
.corner-hint {
  position: absolute;
  right: 36px;
  bottom: 13px;
  z-index: 10;
  display: inline-flex;
  align-items: flex-start;
  gap: 3px;
  color: rgba(54, 54, 58, 0.36);
  pointer-events: none;
  opacity: 1;
  transform: translate(0, 0) scale(1);
  transition:
    opacity 0.4s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.4s cubic-bezier(0.22, 1, 0.36, 1),
    color 0.2s ease;
}

.corner-hint-text {
  font-family: "Segoe Print", "Bradley Hand", "Chalkboard SE", "Kaiti SC", "STKaiti", -apple-system, cursive, sans-serif;
  font-size: 11.5px;
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
  transform: rotate(-2.5deg);
}

.corner-hint-arrow {
  width: 24px;
  height: 17px;
  display: block;
  margin-top: 2px;
  overflow: visible;
  flex-shrink: 0;
}

.corner-hint.is-hidden,
.corner-hint.is-hidden-for-zoom,
.corner-hint.is-turning {
  opacity: 0;
  transform: translate(2px, 2px) scale(0.96);
}

/* Gently highlight the hint when hovering the curled corner while visible */
.sheet-frame:has(.page-corner:hover) .corner-hint:not(.is-hidden):not(.is-hidden-for-zoom):not(.is-turning) {
  color: rgba(44, 44, 46, 0.62);
  transform: translate(1px, 1px);
}

/* 120 FPS GPU sheet-toss transition: old sheet slides away while the fresh sheet settles in */
.sheet-frame.is-settling {
  transition:
    transform 0.46s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.38s ease-out;
}

.sheet-ghost {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 25;
  pointer-events: none;
  transform-origin: center center;
  will-change: transform, opacity;
  transition:
    transform 0.5s cubic-bezier(0.32, 0.04, 0.2, 1),
    opacity 0.44s ease-in;
}

.sheet-ghost-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Organic curled paper corner (SVG) */
.page-corner {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 12;
  width: 54px;
  height: 54px;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  transition: opacity 0.24s ease;
}

.corner-svg {
  width: 34px;
  height: 34px;
  display: block;
  overflow: visible;
  transform-origin: 100% 100%;
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.24s ease;
}

.page-corner:hover .corner-svg {
  transform: scale(1.22);
}

.page-corner:active .corner-svg {
  transform: scale(1.3);
}

.page-corner.is-turning {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.04s linear;
}

.page-corner.is-arriving .corner-svg {
  animation: cornerSettle 0.36s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.page-corner:focus-visible .corner-svg {
  outline: 1.5px solid rgba(44, 44, 46, 0.35);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Zoom reset pill in the bottom-left corner */
.zoom-pill {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 15;
  height: 30px;
  padding: 0 11px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  border: 1px solid var(--border-ui);
  border-radius: 999px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 560;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: transform 0.14s ease, border-color 0.15s ease;
}

.zoom-pill:hover {
  border-color: var(--border-ui-hover);
}

.zoom-pill:active {
  transform: scale(0.94);
}

.zoom-pill[hidden] {
  display: none;
}

.toast {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  max-width: calc(100% - 28px);
  padding: 8px 14px;
  background: rgba(34, 34, 36, 0.88);
  color: #FFFFFF;
  font-size: 12.5px;
  line-height: 1.35;
  text-align: center;
  border-radius: 999px;
  pointer-events: none;
  animation: toastIn 0.2s ease-out both;
}

.toast[hidden] {
  display: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(246, 246, 247, 0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeIn 0.25s ease both;
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  width: 100%;
  max-width: 330px;
  padding: 28px 24px 24px;
  background: #FFFFFF;
  border: 1px solid var(--border-ui);
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
}

.overlay-title {
  font-size: 17px;
  font-weight: 620;
  letter-spacing: -0.015em;
  color: var(--ink);
}

.overlay-desc {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

@keyframes cornerSettle {
  0% {
    opacity: 0;
    transform: scale(0.62);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes softPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

@keyframes dotRipple {
  0% {
    opacity: 0.65;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(3.4);
  }
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (min-width: 720px) {
  .app {
    padding: 8px 18px 14px;
  }
}
