@font-face {
  font-family: "Fredoka";
  src: url("../assets/fonts/fredoka-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F, U+2013-2014, U+2018-2019, U+2022, U+2026, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* CJK only. An English screen never asks for this file. */
@font-face {
  font-family: "Puff TC";
  src: url("../assets/fonts/puff-tc.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+3000-303F, U+3400-4DBF, U+4E00-9FFF, U+F900-FAFF, U+FE30-FE4F, U+FF00-FFEF;
}

:root {
  --paper: #FFF7EF;
  --paper-deep: #F0E0D2;
  --ink: #5C4A42;
  --muted: #8A7368;
  --panel: #FFFBF7;
  --line: #E8D5C6;
  --accent: #C47A56;
  --accent-deep: #A86240;
  --chip: #FFFFFF;
  --warn: #8E463C;
  --shadow: 0 16px 40px rgba(92, 52, 32, 0.12);
  --stage-fallback: #F8E8D8;
  --theme-color: #FFF7EF;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Fredoka", system-ui, sans-serif;
  font-synthesis: none;
}

html.lang-zh body {
  font-family: "Fredoka", "Puff TC", system-ui, sans-serif;
}

html.lang-en #lang .zh-lab {
  font-family: "Fredoka", system-ui, sans-serif;
}

body {
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button, input { font: inherit; color: inherit; }

input { user-select: text; -webkit-user-select: text; }

#app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding:
    calc(10px + var(--sat))
    calc(12px + var(--sar))
    calc(12px + var(--sab))
    calc(12px + var(--sal));
  background:
    radial-gradient(900px 420px at 15% -10%, #fff6ec 0%, transparent 60%),
    var(--paper);
}

header { display: flex; flex-direction: column; gap: 4px; }

.title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

html.lang-zh h1 { font-size: calc(1.7rem * 0.9); }

.tagline {
  margin: 0;
  max-width: 40rem;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.35;
}

html.lang-zh .tagline { font-size: calc(0.98rem * 0.9); }

.top-actions {
  display: flex;
  gap: 8px;
  flex: none;
}

.ghost, .chip, #save {
  border: 2px solid transparent;
  border-radius: 999px;
  min-height: 44px;
  padding: 8px 14px;
  background: var(--panel);
  cursor: pointer;
}

.ghost {
  border-color: var(--line);
  box-shadow: 0 1px 0 rgba(80, 48, 32, 0.04);
}

.ghost[aria-pressed="true"] {
  background: #F6D9CF;
  border-color: var(--accent);
}

#lang { white-space: nowrap; }

#lang .sep { opacity: 0.45; margin: 0 0.2em; }

html.lang-en #lang .en-lab { text-decoration: underline; text-underline-offset: 3px; }
html.lang-zh #lang .zh-lab { text-decoration: underline; text-underline-offset: 3px; }
html.lang-en #lang .zh-lab,
html.lang-zh #lang .en-lab { opacity: 0.45; }

#stage-wrap {
  position: relative;
  flex: 1.45 1 0;
  min-height: 220px;
  border-radius: 28px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--stage-fallback);
}

#stage {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#dock {
  flex: 1 1 0;
  min-height: 0;
  overflow: auto;
  background: var(--panel);
  border-radius: 24px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 10px 28px rgba(92, 52, 32, 0.06);
}

.name-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.86rem;
  color: var(--muted);
}

#puff-name {
  width: 100%;
  min-height: 44px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: #fff;
  padding: 8px 14px;
  outline: none;
}

#puff-name:focus-visible,
button:focus-visible {
  outline: 3px solid #E7A08A;
  outline-offset: 2px;
}

.note {
  margin: 0;
  min-height: 1.1em;
  font-size: 0.8rem;
  color: var(--warn);
}

.note[hidden] { display: none; }

#save {
  background: var(--accent);
  color: #3F241C;
  font-weight: 600;
  box-shadow: 0 5px 0 var(--accent-deep);
}

#save:active { transform: translateY(2px); box-shadow: 0 3px 0 var(--accent-deep); }

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}

legend {
  padding: 0;
  margin: 0 0 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  border-color: var(--line);
  background: var(--chip);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip.is-on,
.chip[aria-pressed="true"] {
  background: #F8D3C6;
  border-color: var(--accent);
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(62, 44, 40, 0.18);
  flex: none;
}

@media (max-width: 480px) {
  h1 { font-size: 1.35rem; }
  html.lang-zh h1 { font-size: calc(1.35rem * 0.9); }
  .tagline { font-size: 0.84rem; }
  html.lang-zh .tagline { font-size: calc(0.84rem * 0.9); }
  #stage-wrap { border-radius: 22px; }
  #dock { border-radius: 20px; }
}

@media (min-width: 960px) and (min-height: 560px) {
  #app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 400px);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "head head"
      "stage dock";
    gap: 12px 14px;
  }
  header { grid-area: head; }
  #stage-wrap { grid-area: stage; min-height: 0; }
  #dock { grid-area: dock; min-height: 0; }
}

noscript p {
  font-family: "Fredoka", system-ui, sans-serif;
  text-align: center;
  padding: 2rem;
}
