:root {
  color-scheme: light;
  --canvas: #ffffff;
  --surface: #f7f7f4;
  --surface-strong: #ecece7;
  --ink: #111111;
  --muted: #62625d;
  --border: #d9d9d3;
  --border-strong: #a6a69f;
  --focus: #db3155;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  font-family: Geist, "SF Pro Display", "PingFang HK", "Noto Sans HK", system-ui, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
  background: var(--canvas);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-width: 280px;
  height: 100%;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  background: var(--canvas);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

button,
input,
a {
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

::selection {
  background: #ffd7e0;
  color: var(--ink);
}

.skip-link {
  position: fixed;
  z-index: 20;
  inset-block-start: 8px;
  inset-inline-start: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #ffffff;
  font-size: 14px;
  line-height: 20px;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform 180ms var(--ease);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 20px 24px 16px;
  text-align: center;
}

.header-inner {
  position: relative;
  display: grid;
  min-height: 54px;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.site-header h1 {
  grid-column: 2;
  margin: 0;
  font-size: clamp(2rem, 3.4vw, 3rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.045em;
  text-wrap: balance;
}

.language-switcher {
  display: inline-flex;
  grid-column: 3;
  justify-self: end;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.language-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 11px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  line-height: 20px;
  white-space: nowrap;
  cursor: pointer;
  transition:
    color 180ms var(--ease),
    background-color 180ms var(--ease),
    transform 180ms var(--ease);
}

.language-button[aria-pressed="true"] {
  background: var(--canvas);
  color: var(--ink);
  box-shadow: 0 1px 3px rgb(17 17 17 / 10%);
}

.locale-short {
  display: none;
}

.creator {
  display: grid;
  min-height: 0;
  height: 100%;
  grid-template-columns: minmax(0, 560px) minmax(400px, 480px);
  align-items: stretch;
  justify-content: center;
  gap: 32px;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 0 24px 24px;
  overflow: hidden;
}

.preview-column,
.controls-column {
  min-width: 0;
  min-height: 0;
}

.preview-column {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.preview-frame {
  position: relative;
  overflow: hidden;
  width: min(100%, calc(100dvh - 244px));
  max-width: 560px;
  aspect-ratio: 1;
  align-self: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow:
    0 1px 2px rgb(17 17 17 / 4%),
    0 18px 48px rgb(17 17 17 / 7%);
  isolation: isolate;
}

#preview {
  display: block;
  width: 100%;
  height: 100%;
  opacity: 1;
  transition: opacity 220ms var(--ease), transform 220ms var(--ease);
}

.preview-frame[data-loading="true"] #preview {
  opacity: 0;
  transform: scale(0.98);
}

.preview-loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--surface);
  transition: opacity 220ms var(--ease), visibility 220ms var(--ease);
}

.preview-loader::after {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: var(--surface-strong);
  content: "";
  animation: breathe 1200ms var(--ease) infinite alternate;
}

.preview-frame[data-loading="false"] .preview-loader {
  visibility: hidden;
  opacity: 0;
}

.primary-actions,
.utility-actions {
  display: grid;
  gap: 12px;
}

.primary-actions {
  grid-template-columns: 1fr;
  margin-top: 16px;
}

.utility-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 10px;
}

.button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 650;
  line-height: 24px;
  text-decoration: none;
  cursor: pointer;
  transition:
    color 180ms var(--ease),
    background-color 180ms var(--ease),
    border-color 180ms var(--ease),
    transform 180ms var(--ease);
}

.button .export-size {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 16px;
  white-space: nowrap;
}

.button-primary {
  background: var(--ink);
  color: #ffffff;
}

.button-primary .export-size {
  background: #343434;
  color: #ffffff;
}

.button-label {
  min-width: 0;
}

.button-secondary {
  border-color: var(--border);
  background: var(--canvas);
  color: var(--ink);
}

.button:active:not(:disabled),
.category-tab:active:not(:disabled),
.language-button:active,
.hat-option:active,
.eye-option:active,
.mouth-option:active {
  transform: scale(0.96);
}

.button:disabled,
.category-tab:disabled,
.color-input:disabled {
  cursor: wait;
  opacity: 0.5;
}

.status {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
  text-align: center;
  text-wrap: pretty;
}

.status[data-error="true"] {
  color: #a31937;
}

.controls-column {
  display: grid;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  padding-top: 8px;
  overflow: hidden;
}

.category-tabs {
  display: grid;
  grid-auto-columns: minmax(68px, 1fr);
  grid-auto-flow: column;
  gap: 6px;
  padding-bottom: 16px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.category-tab {
  width: 100%;
  min-height: 44px;
  padding: 8px 2px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--canvas);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition:
    color 180ms var(--ease),
    background-color 180ms var(--ease),
    border-color 180ms var(--ease),
    transform 180ms var(--ease);
}

.category-tab[aria-selected="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: #ffffff;
}

.options-panel {
  min-height: 0;
  padding: 0 10px 32px 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--border-strong) transparent;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.panel-heading {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 4px;
  padding: 4px 0 14px;
  background: var(--canvas);
}

.panel-heading h3 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  line-height: 28px;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.panel-heading > span {
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
}

.custom-color {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  min-height: 112px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}

.custom-color-copy {
  min-width: 0;
}

.custom-color label {
  font-size: 14px;
  font-weight: 650;
  line-height: 20px;
  cursor: pointer;
}

.custom-color p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
  text-wrap: pretty;
}

.custom-color-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-input {
  width: 72px;
  height: 72px;
  flex: 0 0 72px;
  padding: 4px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--canvas);
  cursor: pointer;
}

.color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-input::-webkit-color-swatch {
  border: 0;
  border-radius: var(--radius-sm);
}

.color-input::-moz-color-swatch {
  border: 0;
  border-radius: var(--radius-sm);
}

.color-value {
  min-width: 64px;
  color: var(--ink);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 16px;
  text-transform: uppercase;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  border: 0;
  margin: -1px;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.hat-picker {
  min-width: 0;
  padding: 0;
  border: 0;
  margin: 0;
}

.hat-collection + .hat-collection {
  padding-top: 24px;
  border-top: 1px solid var(--border);
  margin-top: 28px;
}

.hat-collection-title {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 20px;
}

.hat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.hat-option {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 138px;
  grid-template-rows: 96px auto;
  align-items: center;
  justify-items: center;
  padding: 8px 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  cursor: pointer;
  transition:
    background-color 180ms var(--ease),
    border-color 180ms var(--ease),
    box-shadow 180ms var(--ease),
    transform 180ms var(--ease);
}

.hat-option:has(.hat-radio:checked) {
  border-color: var(--ink);
  background: var(--canvas);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.hat-option:has(.hat-radio:disabled) {
  cursor: wait;
  opacity: 0.5;
}

.hat-option:has(.hat-radio:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.hat-preview {
  display: block;
  width: 100%;
  height: 96px;
}

.hat-none-glyph {
  position: relative;
  width: 54px;
  height: 54px;
  align-self: center;
  border: 2px solid var(--border-strong);
  border-radius: 999px;
}

.hat-none-glyph::after {
  position: absolute;
  inset-block-start: 25px;
  inset-inline-start: 5px;
  width: 41px;
  height: 2px;
  border-radius: 999px;
  background: var(--border-strong);
  content: "";
  transform: rotate(-45deg);
  transform-origin: center;
}

.hat-name {
  max-width: 100%;
  font-size: 14px;
  font-weight: 650;
  line-height: 20px;
  text-align: center;
  text-wrap: balance;
}

.hat-option[data-asset-error="true"] .hat-preview {
  opacity: 0.25;
}

.mouth-option[data-asset-error="true"] .mouth-preview {
  opacity: 0.25;
}

.eye-picker {
  min-width: 0;
  padding: 0;
  border: 0;
  margin: 0;
}

.eye-collection + .eye-collection {
  padding-top: 24px;
  border-top: 1px solid var(--border);
  margin-top: 28px;
}

.eye-collection-title {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 20px;
}

.eye-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.eye-option {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 116px;
  grid-template-rows: 76px auto;
  align-items: center;
  justify-items: center;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  cursor: pointer;
  transition:
    background-color 180ms var(--ease),
    border-color 180ms var(--ease),
    box-shadow 180ms var(--ease),
    transform 180ms var(--ease);
}

.eye-option:has(.eye-radio:checked) {
  border-color: var(--ink);
  background: var(--canvas);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.eye-option:has(.eye-radio:disabled) {
  cursor: wait;
  opacity: 0.5;
}

.eye-option:has(.eye-radio:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.eye-preview {
  display: block;
  width: 100%;
  height: 76px;
}

.eye-name {
  max-width: 100%;
  font-size: 12px;
  font-weight: 650;
  line-height: 16px;
  text-align: center;
  text-wrap: balance;
}

.mouth-picker {
  min-width: 0;
  padding: 0;
  border: 0;
  margin: 0;
}

.mouth-collection + .mouth-collection {
  padding-top: 24px;
  border-top: 1px solid var(--border);
  margin-top: 28px;
}

.mouth-collection-title {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 20px;
}

.mouth-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.mouth-option {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 128px;
  grid-template-rows: 88px auto;
  align-items: center;
  justify-items: center;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  cursor: pointer;
  transition:
    background-color 180ms var(--ease),
    border-color 180ms var(--ease),
    box-shadow 180ms var(--ease),
    transform 180ms var(--ease);
}

.mouth-option:has(.mouth-radio:checked) {
  border-color: var(--ink);
  background: var(--canvas);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.mouth-option:has(.mouth-radio:disabled) {
  cursor: wait;
  opacity: 0.5;
}

.mouth-option:has(.mouth-radio:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.mouth-preview {
  display: block;
  width: 100%;
  height: 88px;
}

.mouth-name {
  max-width: 100%;
  font-size: 12px;
  font-weight: 650;
  line-height: 16px;
  text-align: center;
  text-wrap: balance;
}

.button:focus-visible,
.category-tab:focus-visible,
.language-button:focus-visible,
.color-input:focus-visible,
.options-panel:focus-visible,
.not-found a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.not-found {
  display: grid;
  place-items: center;
  padding: 24px;
}

.not-found main {
  display: grid;
  justify-items: center;
  gap: 24px;
  text-align: center;
}

.not-found h1 {
  margin: 0;
  font-size: 30px;
  line-height: 36px;
}

.mini-cat {
  font-size: 60px;
  line-height: 1;
}

noscript {
  display: block;
  padding: 24px;
  color: #a31937;
  text-align: center;
}

@keyframes breathe {
  from {
    opacity: 0.35;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (hover: hover) and (pointer: fine) {
  .button:hover:not(:disabled),
  .category-tab:hover:not(:disabled),
  .language-button:hover,
  .hat-option:hover:not(:has(.hat-radio:disabled)),
  .eye-option:hover:not(:has(.eye-radio:disabled)),
  .mouth-option:hover:not(:has(.mouth-radio:disabled)) {
    transform: translateY(-2px);
  }

  .button-primary:hover:not(:disabled) {
    background: #2c2c2c;
  }

  .button-secondary:hover:not(:disabled),
  .category-tab:hover:not(:disabled),
  .hat-option:hover:not(:has(.hat-radio:disabled)),
  .eye-option:hover:not(:has(.eye-radio:disabled)),
  .mouth-option:hover:not(:has(.mouth-radio:disabled)) {
    border-color: var(--border-strong);
    background: var(--surface);
  }

  .hat-option:hover:has(.hat-radio:checked) {
    border-color: var(--ink);
    background: var(--canvas);
  }

  .eye-option:hover:has(.eye-radio:checked) {
    border-color: var(--ink);
    background: var(--canvas);
  }

  .mouth-option:hover:has(.mouth-radio:checked) {
    border-color: var(--ink);
    background: var(--canvas);
  }

  .category-tab[aria-selected="true"]:hover:not(:disabled) {
    border-color: var(--ink);
    background: var(--ink);
    color: #ffffff;
  }
}

@media (max-width: 960px) {
  .site-header {
    padding: 12px 16px 10px;
  }

  .header-inner {
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .site-header h1 {
    grid-column: 1;
    font-size: clamp(1.75rem, 7vw, 2.25rem);
    line-height: 1.05;
  }

  .language-switcher {
    grid-column: 1;
    justify-self: center;
  }

  .language-button {
    min-height: 36px;
    padding: 5px 10px;
  }

  .creator {
    grid-template-columns: minmax(0, 600px);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 12px;
    padding: 0 max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }

  .preview-frame {
    width: min(100%, clamp(190px, 33dvh, 300px));
    border-radius: var(--radius-lg);
  }

  .primary-actions {
    margin-top: 10px;
  }

  .utility-actions {
    margin-top: 6px;
  }

  .button {
    min-height: 44px;
    padding-block: 7px;
  }

  .status {
    min-height: 16px;
    margin-top: 4px;
  }

  .controls-column {
    padding-top: 0;
  }

  .category-tabs {
    padding-bottom: 10px;
  }

  .options-panel {
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 540px) {
  .category-tab {
    padding-inline: 2px;
    font-size: 11px;
  }

  .eye-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .mouth-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
}

@media (max-width: 360px) {
  .locale-wide {
    display: none;
  }

  .locale-short {
    display: inline;
  }

  .button .export-size {
    padding-inline: 6px;
    font-size: 11px;
  }

  .custom-color {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .hat-grid {
    gap: 8px;
  }

  .hat-option {
    min-height: 124px;
    grid-template-rows: 82px auto;
    padding-inline: 6px;
  }

  .hat-preview {
    height: 82px;
  }
}

@media (max-width: 960px) and (max-height: 600px) and (orientation: landscape) {
  .site-header {
    padding-block: 8px;
  }

  .header-inner {
    min-height: 40px;
    grid-template-columns: 1fr auto 1fr;
    gap: 0;
  }

  .site-header h1 {
    grid-column: 2;
    font-size: clamp(1.35rem, 4vw, 1.75rem);
  }

  .language-switcher {
    grid-column: 3;
    justify-self: end;
  }

  .locale-wide {
    display: none;
  }

  .locale-short {
    display: inline;
  }

  .creator {
    grid-template-columns: minmax(230px, 42%) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 16px;
  }

  .preview-frame {
    width: min(100%, calc(100dvh - 190px));
  }

  .primary-actions {
    margin-top: 6px;
  }

  .utility-actions {
    margin-top: 5px;
  }

  .status {
    min-height: 14px;
    margin-top: 2px;
    line-height: 14px;
  }
}

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

  .button,
  .category-tab,
  .language-button,
  .hat-option,
  .eye-option,
  .mouth-option,
  .preview-loader::after {
    transform: none !important;
  }
}
