:root {
  color-scheme: light dark;
  --bg: #fff;
  --text: #1c1c1e;
  --tertiary: rgba(60, 60, 67, 0.3);
  --secondary: rgba(60, 60, 67, 0.6);
  --separator: rgba(60, 60, 67, 0.12);
  --tint: #007aff;
  font-family: ui-rounded, -apple-system, "SF Pro Rounded", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --text: #f2f2f7;
    --tertiary: rgba(235, 235, 245, 0.3);
    --secondary: rgba(235, 235, 245, 0.6);
    --separator: rgba(235, 235, 245, 0.14);
    --tint: #0a84ff;
  }
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

main {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

/* Banner or saved-phrase history */

#banner {
  border-radius: 16px;
  margin-top: 8px;
}

#history {
  width: min(640px, 100%);
  max-height: 33dvh;
  overflow-y: auto;
  border: 1px solid var(--separator);
  border-radius: 12px;
}

#history p {
  padding: 8px 12px;
  border-bottom: 1px solid var(--separator);
}

#history p:last-child { border-bottom: none; }

/* The canvas: tap to add, swipe to undo/save */

#canvas {
  flex: 1;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  min-height: 0;
}

#phrase {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  max-width: min(640px, 100%);
  font-size: clamp(1.75rem, 6vw, 2.5rem);
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
}

#phrase.empty {
  color: var(--tertiary);
}

#phrase .word {
  animation: pop 0.25s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
}

/* Share and About */

#controls {
  display: flex;
  gap: 20px;
}

#controls button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 22px;
  background: transparent;
  color: var(--tint);
  cursor: pointer;
}

#controls button:hover { background: color-mix(in srgb, var(--tint) 12%, transparent); }
#controls button:active { opacity: 0.5; }

/* About sheet */

dialog {
  margin: auto;
  width: min(640px, calc(100% - 32px));
  max-height: 80dvh;
  border: none;
  border-radius: 16px;
  padding: 20px 24px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

dialog h1 {
  font-size: 1.1rem;
  font-weight: 600;
}

dialog p { margin-bottom: 12px; }

dialog hr {
  border: none;
  border-top: 1px solid var(--separator);
  margin: 16px 0;
}

#closeAbout {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 15px;
  background: var(--separator);
  color: var(--secondary);
  font-size: 0.9rem;
  cursor: pointer;
}

#license {
  font-size: 0.75rem;
  color: var(--secondary);
  white-space: pre-wrap;
}

kbd {
  font-family: inherit;
  padding: 1px 5px;
  border: 1px solid var(--separator);
  border-radius: 4px;
  font-size: 0.85em;
}

/* Copied-to-clipboard toast */

#toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  translate: -50% 0;
  padding: 10px 18px;
  border-radius: 20px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.9rem;
  animation: fade 2s forwards;
  pointer-events: none;
}

@keyframes fade {
  0%, 75% { opacity: 1; }
  100% { opacity: 0; }
}
