@font-face {
  font-family: "BestTen DOT";
  src: url("./fonts/BestTen-DOT-r12.otf") format("opentype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "TKSKbeat Symbols";
  src: local("Segoe UI Symbol"), local("Apple Symbols"), local("Noto Sans Symbols 2");
  unicode-range: U+00D7, U+25A0, U+25B6, U+25CF;
}

:root {
  color-scheme: light;
  --ink: #201f25;
  --cream: #fff8df;
  --yellow: #ffd942;
  --orange: #ff7448;
  --pink: #f45c9a;
  --blue: #4b9cff;
  --mint: #68d8b4;
  --lcd: #cfe59a;
  --lcd-ink: #29433a;
  --shadow: 0 8px 0 rgba(52, 40, 38, 0.24);
  --ui-font: "BestTen DOT", system-ui, sans-serif;
  font-family: var(--ui-font);
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, rgba(255,255,255,.75) 0 5%, transparent 6%),
    linear-gradient(145deg, #62d6bd 0%, #35a6d9 55%, #5272d7 100%);
  overscroll-behavior: none;
}

button, select { font: inherit; }
button { color: inherit; }

.shell {
  width: min(100%, 760px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(20px, env(safe-area-inset-bottom));
  background: var(--yellow);
  box-shadow: 0 0 50px rgba(18, 36, 64, .28);
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 6px 12px;
}

.brand-lockup { flex: 1 1 auto; min-width: 0; }

.header-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.eyebrow {
  margin: 0 0 2px;
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .14em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(2rem, 9vw, 3.5rem); line-height: .92; letter-spacing: -.08em; }
.brand-sound { appearance: none; display: block; max-width: 100%; padding: 0; border: 0; background: transparent; font: inherit; line-height: inherit; letter-spacing: inherit; cursor: pointer; touch-action: manipulation; }
.brand-logo { display: block; width: min(340px, 100%); height: auto; }
.brand-sound:active { transform: translateY(2px) scale(.98); }
h2 { margin-bottom: 0; font-size: .92rem; letter-spacing: .08em; }

.credit-button,
.new-beat-button {
  appearance: none;
  display: grid;
  place-items: center;
  width: 70px;
  height: 48px;
  padding: 0;
  border: 3px solid var(--ink);
  border-radius: 2px;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.3), 0 4px 0 rgba(32,31,37,.25);
  font: 900 .62rem/1 var(--ui-font);
  letter-spacing: .05em;
  cursor: pointer;
  touch-action: manipulation;
}
.credit-button { background: #f8c72a; }
.new-beat-button { background: var(--pink); color: white; }
.credit-button:active,
.new-beat-button:active { transform: translateY(3px); box-shadow: inset 0 2px 0 rgba(32,31,37,.25); }

.panel, .lcd {
  border: 3px solid var(--ink);
  border-radius: 4px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.tab-panel[hidden] { display: none; }
.tab-lead { margin: 0 4px 10px; font-size: clamp(.86rem, 3.8vw, 1rem); font-weight: 900; text-align: center; }

.lcd {
  position: relative;
  display: grid;
  grid-template-columns: 66px 1fr;
  gap: 12px;
  align-items: center;
  min-height: 104px;
  padding: 14px 14px 22px;
  color: var(--lcd-ink);
  background: var(--lcd);
  overflow: hidden;
}

.lcd-spectrum {
  position: absolute;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  color: var(--lcd-ink);
  opacity: .16;
  pointer-events: none;
}

.lcd::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(41,67,58,.05) 4px);
}

.lcd-character {
  position: relative;
  z-index: 2;
  width: 62px;
  height: 62px;
  background: url("./images/lcd/lcd-chick-idle.png") center / 88px 88px no-repeat;
  image-rendering: pixelated;
  transform-origin: bottom center;
}

.lcd-character.is-beat { background-image: url("./images/lcd/lcd-chick-beat.png"); }
.lcd-character .eye,
.lcd-character .mouth { display: none; }
.lcd-character.bop { animation: bop .2s ease-out; }
@keyframes bop { 50% { transform: translateY(-8px) rotate(-4deg) scale(1.05); } }

.lcd-copy { position: relative; z-index: 2; display: flex; flex-direction: column; justify-content: center; min-width: 0; padding-block: 2px; }
.lcd-copy strong { display: block; min-height: 1.45em; padding-block: .06em; font-family: "TKSKbeat Symbols", var(--ui-font); font-size: clamp(.74rem, 3.6vw, 1.1rem); line-height: 1.4; letter-spacing: -.02em; white-space: nowrap; }
.lcd-copy span { display: block; min-height: 1.45em; padding-block: .06em; font-size: clamp(.62rem, 2.8vw, .86rem); font-weight: 900; line-height: 1.4; letter-spacing: -.03em; white-space: nowrap; overflow: hidden; }

.meter { position: absolute; z-index: 3; left: 0; right: 0; bottom: 0; height: 9px; border-top: 3px solid var(--ink); background: rgba(255,255,255,.28); }
.meter i { display: block; width: 0; height: 100%; background: var(--lcd-ink); transition: width 80ms linear; }

.operation-panel {
  padding: 10px;
  background: var(--cream);
}

.operation-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.operation-grid .play-toggle { grid-column: 1 / span 2; }
.operation-grid[data-active-tab="voice"] .play-toggle { grid-column: 1; }
.operation-grid .rec { grid-column: 2; }
.operation-grid .view-toggle { grid-column: 3 / span 2; }

.view-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  min-width: 0;
  padding: 5px;
  border: 3px solid var(--ink);
  border-radius: 5px;
  background: var(--ink);
  box-shadow: 0 5px 0 rgba(32,31,37,.28);
}

.view-toggle::before { display: none; }

.view-toggle button {
  position: relative;
  min-width: 0;
  min-height: 54px;
  padding: 4px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: white;
  box-shadow: inset 0 -5px 0 rgba(32,31,37,.14), 0 4px 0 rgba(255,255,255,.2);
  font-size: clamp(.7rem, 3vw, .9rem);
  font-weight: 900;
  transition: transform 90ms ease, box-shadow 90ms ease, background-color 90ms linear;
  touch-action: manipulation;
}

.view-toggle button[aria-selected="true"] {
  color: white;
  transform: translateY(3px);
  box-shadow: inset 0 4px 0 rgba(32,31,37,.22);
}
.view-toggle button[data-tab="pico"][aria-selected="true"] { background: var(--blue); }
.view-toggle button[data-tab="voice"][aria-selected="true"] { background: var(--pink); }
.view-toggle button[aria-selected="false"]:active { transform: translateY(2px); box-shadow: inset 0 2px 0 rgba(32,31,37,.18); }
.operation-grid[data-recording="true"] .view-toggle button[data-tab="voice"]::after {
  content: "●";
  position: absolute;
  top: 4px;
  right: 5px;
  color: white;
  font-size: .52rem;
  animation: pulse 1s steps(2, end) infinite;
}

.control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 62px;
  border: 3px solid var(--ink);
  border-radius: 2px;
  background: white;
  box-shadow: 0 4px 0 var(--ink);
  font-size: 1.15rem;
  font-weight: 900;
  touch-action: manipulation;
}
.control[hidden] { display: none; }
.control-icon {
  font-family: "TKSKbeat Symbols", system-ui, sans-serif;
  font-size: 1.05rem;
  font-weight: 400;
  line-height: 1;
}
.control-label { min-width: 0; font-size: clamp(.68rem, 3vw, .84rem); white-space: nowrap; }
.control:active { transform: translateY(4px); box-shadow: none; }
.control.play-toggle { background: var(--mint); }
.control.rec[aria-pressed="true"] { background: var(--pink); color: white; animation: pulse 1s steps(2, end) infinite; }
.control.rec[data-counting="true"] { background: var(--yellow); animation: pulse .5s steps(2, end) infinite; }
.control.finish { background: var(--orange); }
@keyframes pulse { 50% { filter: brightness(1.15); } }

.segmented { display: grid; grid-template-columns: 1fr 1fr; }
.segmented button { min-height: 42px; border: 2px solid var(--ink); background: transparent; font-size: .76rem; font-weight: 900; }
.segmented button:first-child { border-radius: 2px 0 0 2px; }
.segmented button:last-child { border-radius: 0 2px 2px 0; border-left: 0; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: white; }
.record-mode { margin: -3px 0 12px; padding: 6px; border: 3px solid var(--ink); border-radius: 2px; background: var(--cream); box-shadow: var(--shadow); }

.preset-panel, .pad-panel { padding: 13px; background: var(--cream); }
.preset-panel { background: linear-gradient(145deg, #fff8df 0%, #fff0b7 100%); }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.section-heading small { font-family: var(--ui-font); font-size: .67rem; }
.preset-grid { display: grid; gap: 9px; }
.track-pattern-row {
  display: grid;
  grid-template-columns: minmax(82px, .65fr) minmax(0, 2.35fr);
  gap: 10px;
  align-items: center;
  padding: 7px;
  border: 2px solid var(--ink);
  border-radius: 5px;
  background: rgba(255,255,255,.64);
  box-shadow: 0 4px 0 rgba(32,31,37,.16);
}
.track-pattern-name {
  padding-left: 4px;
  font-size: clamp(.68rem, 2.8vw, .82rem);
  font-weight: 900;
  letter-spacing: .04em;
}
.track-pattern-buttons { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; }
.track-pattern-button {
  --pattern-color: var(--pink);
  --pattern-ink: white;
  min-width: 0;
  min-height: 44px;
  padding: 0;
  border: 3px solid var(--ink);
  border-radius: 5px;
  color: var(--pattern-ink);
  background: var(--pattern-color);
  box-shadow: inset 0 3px 0 rgba(255,255,255,.36), 0 6px 0 var(--ink);
  font-size: clamp(.9rem, 4vw, 1.2rem);
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  transition: transform 80ms ease, box-shadow 80ms ease, filter 80ms linear;
  touch-action: manipulation;
}
.track-pattern-button.pattern-1 { --pattern-color: #f45c9a; --pattern-ink: white; }
.track-pattern-button.pattern-2 { --pattern-color: #4b9cff; --pattern-ink: white; }
.track-pattern-button.pattern-3 { --pattern-color: #68d8b4; --pattern-ink: var(--ink); }
.track-pattern-button.pattern-4 { --pattern-color: #ffb52e; --pattern-ink: var(--ink); }
.track-pattern-button.pattern-5 { --pattern-color: #9b72e8; --pattern-ink: white; }
.track-pattern-button[aria-pressed="true"] {
  transform: translateY(6px);
  box-shadow: inset 0 4px 0 rgba(32,31,37,.25), 0 0 0 var(--ink);
  filter: saturate(1.08) brightness(.94);
}
.track-pattern-button[aria-pressed="false"]:active { transform: translateY(3px); box-shadow: inset 0 2px 0 rgba(32,31,37,.18), 0 3px 0 var(--ink); }
.track-pattern-button:disabled { cursor: default; }

.pad-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.pad {
  position: relative;
  aspect-ratio: 1;
  border: 3px solid var(--ink);
  border-radius: 2px;
  background: var(--pad-color, var(--pink));
  box-shadow: 0 5px 0 var(--ink);
  font-size: clamp(.7rem, 3vw, .95rem);
  font-weight: 900;
  touch-action: none;
  user-select: none;
}
.pad::after { content: attr(data-number); position: absolute; top: 6px; right: 8px; font: 700 .58rem var(--ui-font); opacity: .65; }
.pad.active { transform: translateY(5px) scale(.98); box-shadow: none; filter: brightness(1.2); }

.finish-panel { margin: 2px 0 16px; }
.finish-panel .finish { width: 100%; min-height: 58px; }
.finish-panel .finish span { font-size: .84rem; }

footer { display: flex; justify-content: space-between; padding: 4px 5px; font: 800 .6rem var(--ui-font); }

button:focus-visible, select:focus-visible { outline: 4px solid white; outline-offset: 2px; }
button:disabled, select:disabled { opacity: .45; cursor: not-allowed; }

.credits-dialog {
  width: min(calc(100% - 24px), 520px);
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  overflow: visible;
}
.credits-dialog::backdrop { background: rgba(30, 31, 50, .82); }
.credits-card { max-height: calc(100dvh - 32px); overflow-y: auto; padding: 24px; border: 4px solid var(--ink); border-radius: 4px; background: var(--yellow); box-shadow: 0 10px 0 var(--ink); text-align: center; }
.credits-card > .eyebrow { margin-bottom: 5px; }
.credits-card h2 { font-size: clamp(2rem, 9vw, 3rem); letter-spacing: -.04em; }
.credits-list { display: grid; grid-template-columns: minmax(7.5rem, .8fr) 1.2fr; gap: 10px 18px; margin: 22px 0; text-align: left; }
.credits-list dt { font-size: .68rem; font-weight: 900; letter-spacing: .05em; }
.credits-list dd { margin: 0; font-size: .78rem; font-weight: 900; line-height: 1.55; }
.credits-divider { height: 4px; margin: 20px 0; background: var(--ink); box-shadow: 0 5px 0 rgba(32,31,37,.18); }
.credits-note h3 { margin: 0 0 10px; color: var(--pink); font-size: 1.35rem; }
.credits-note p { margin: 0 0 12px; font: 800 .7rem/1.65 var(--ui-font); }
.credits-note .credits-unofficial { display: inline-block; margin: 4px 0 14px; padding: 6px 9px; border: 3px solid var(--ink); background: var(--cream); font-size: .75rem; letter-spacing: .12em; }
.credits-close { width: 100%; min-height: 48px; margin-top: 8px; border: 3px solid var(--ink); border-radius: 2px; background: var(--mint); box-shadow: 0 4px 0 var(--ink); font-weight: 900; }
.credits-close:active { transform: translateY(4px); box-shadow: none; }

.result {
  position: fixed;
  z-index: 2147483647;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(30, 31, 50, .82);
  isolation: isolate;
  contain: paint;
  transform: translateZ(0);
}
.result[hidden] { display: none; }
.result-card { position: relative; z-index: 1; width: min(100%, 440px); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 24px; border: 4px solid var(--ink); border-radius: 4px; background: var(--yellow); box-shadow: 0 12px 0 var(--ink); text-align: center; }
.result-visual-frame { width: min(100%, 360px); margin: 0 auto 16px; padding: 10px; border: 4px solid var(--ink); border-radius: 2px; background: var(--cream); box-shadow: 0 6px 0 var(--ink); }
.result-visual-stage { position: relative; width: 100%; aspect-ratio: 1; overflow: hidden; background: var(--cream); }
.result-visual-layer { display: block; position: absolute; image-rendering: pixelated; opacity: var(--layer-opacity, 1); }
.result-visual-layer[data-layer-mode="cover"] { inset: 0; width: 100%; height: 100%; object-fit: cover; }
.result-visual-layer[data-layer-mode="contain"] {
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: var(--layer-position, 50% 50%);
  transform: scale(var(--layer-scale, 1));
  transform-origin: var(--layer-position, 50% 50%);
}
.result-visual-character {
  filter: drop-shadow(2px 0 #fff8df) drop-shadow(-2px 0 #fff8df) drop-shadow(0 2px #fff8df) drop-shadow(0 -2px #fff8df) drop-shadow(0 4px 2px rgba(32, 31, 37, .38));
}
.result-visual-layer[data-layer-mode="placed"] {
  left: var(--layer-left, 0%);
  top: var(--layer-top, 0%);
  width: var(--layer-width, 25%);
  height: auto;
  transform: rotate(var(--layer-rotate, 0deg));
  transform-origin: center;
}
.result-visual-sticker {
  filter: drop-shadow(2px 3px 0 rgba(32, 31, 37, .32));
  pointer-events: none;
}
.result-visual-greeting {
  filter: drop-shadow(2px 3px 0 rgba(32, 31, 37, .42));
  pointer-events: none;
}
.result-visual-corner-label {
  filter: drop-shadow(1px 2px 0 rgba(32, 31, 37, .32));
  pointer-events: none;
}
.result-actions { display: grid; gap: 9px; }
.result-actions button { min-height: 48px; border: 3px solid var(--ink); border-radius: 2px; background: white; box-shadow: 0 4px 0 var(--ink); font-weight: 900; }
.result-actions button[hidden] { display: none; }
.result-actions button:first-child { background: var(--mint); }
.result-actions .share-image { background: var(--blue); color: white; }
.result-actions .back-edit { background: #fff0b7; }
.result-actions .create-own-beat { background: var(--pink); color: white; }
.result-play-icon { display: inline-block; min-width: 1.25em; margin-right: .2em; font-family: "TKSKbeat Symbols", system-ui, sans-serif; font-weight: 400; }
.result-error { margin: 0 0 12px; padding: 10px; border: 3px solid var(--ink); background: #ffd5c8; color: #8c102c; font-size: .72rem; font-weight: 900; line-height: 1.5; }
.result-error[hidden] { display: none; }

.sound-editor {
  padding: 14px;
  background: #f2f4ff;
  box-shadow: 0 8px 0 rgba(32, 31, 37, .4);
}
.sound-editor-heading { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; }
.sound-editor-heading h2 { margin: 0; font-size: 1.05rem; }
.sound-editor-heading small { display: block; margin-top: 3px; font-size: .66rem; }
.sound-editor-badge { padding: 5px 7px; border: 2px solid var(--ink); background: var(--orange); color: white; font-size: .58rem; letter-spacing: .08em; }
.sound-editor-tabs { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 12px; border: 2px solid var(--ink); }
.sound-editor-tabs button { min-height: 42px; border: 0; border-right: 2px solid var(--ink); background: white; font-weight: 900; }
.sound-editor-tabs button:last-child { border-right: 0; }
.sound-editor-tabs button[aria-selected="true"] { background: var(--ink); color: white; }
.sound-editor-selects { display: grid; grid-template-columns: 1fr 1.5fr; gap: 8px; margin-bottom: 12px; }
.sound-editor-selects label { font-size: .67rem; font-weight: 900; }
.sound-editor-selects select { display: block; width: 100%; min-height: 40px; margin-top: 4px; padding: 5px; border: 2px solid var(--ink); background: white; font-size: .7rem; }
.sound-editor-selects .sound-editor-check { grid-column: 1 / -1; display: flex; align-items: center; min-height: 40px; padding: 7px 9px; border: 2px solid var(--ink); background: white; }
.sound-editor-check input { width: 20px; height: 20px; margin: 0 5px 0 0; accent-color: var(--blue); }
.sound-editor-parameters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
.sound-editor-parameter { display: grid; grid-template-columns: minmax(76px, .75fr) minmax(100px, 1.5fr) 76px; gap: 7px; align-items: center; min-width: 0; }
.sound-editor-parameter label { font-size: .65rem; font-weight: 900; }
.sound-editor-parameter label small { font-size: .55rem; opacity: .7; }
.sound-editor-parameter input[type="range"] { width: 100%; min-width: 0; accent-color: var(--blue); }
.sound-editor-parameter input[type="number"] { width: 100%; min-width: 0; min-height: 34px; padding: 4px 5px; border: 2px solid var(--ink); background: white; font: 800 .68rem var(--ui-font); }
.sound-editor-parameter input[aria-invalid="true"] { border-color: #c32945; background: #fff0f3; }
.sound-editor-parameter[data-disabled="true"] { opacity: .45; }
.sound-editor-json-label { display: block; margin-top: 14px; font-size: .65rem; font-weight: 900; }
.sound-editor textarea { width: 100%; margin-top: 5px; padding: 8px; resize: vertical; border: 2px solid var(--ink); background: #fff; font: 12px/1.45 ui-monospace, Consolas, monospace; }
.sound-editor-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 8px; }
.sound-editor-actions button { min-height: 42px; padding: 6px; border: 2px solid var(--ink); background: var(--mint); box-shadow: 0 3px 0 var(--ink); font-size: .68rem; font-weight: 900; }
.sound-editor-actions button:active { transform: translateY(3px); box-shadow: none; }
.sound-editor-actions .sound-editor-reset { background: #ffd5c8; }
.sound-editor-status { min-height: 1.4em; margin: 9px 0 0; font-size: .67rem; font-weight: 900; }
.sound-editor-status[data-type="error"] { color: #b31835; }
.sound-editor-status[data-type="warning"] { color: #8a5700; }

@media (max-width: 480px) {
  .shell { padding-left: 10px; padding-right: 10px; }
  .brand-row { gap: 6px; padding-inline: 2px; }
  .header-actions { gap: 4px; }
  .credit-button, .new-beat-button { width: 62px; height: 44px; font-size: .55rem; }
  .track-pattern-row { grid-template-columns: 1fr; gap: 5px; padding: 6px; }
  .track-pattern-name { padding-left: 2px; font-size: .68rem; }
  .track-pattern-buttons { gap: 6px; }
  .track-pattern-button { min-height: 46px; }
  .operation-grid { gap: 5px; }
  .control { min-height: 57px; font-size: 1rem; }
  .view-toggle button { min-height: 57px; }
  .sound-editor-parameters { grid-template-columns: 1fr; }
  .sound-editor-parameter { grid-template-columns: 72px minmax(90px, 1fr) 70px; }
  .sound-editor-actions { grid-template-columns: 1fr; }
  .credits-card { padding: 20px 16px; }
  .credits-list { grid-template-columns: 1fr; gap: 4px; }
  .credits-list dd { margin-bottom: 8px; }
}

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








