@font-face {
  font-family: Yomogi;
  src: url("assets/Yomogi-Game.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: light;
  --background: #fdfcfb;
  --ink: #282522;
  --red: #b64e58;
  --red-line: #cd717a;
  --piece-width: clamp(76px, 23vw, 148px);
  --piece-height: clamp(42px, min(13vw, 10dvh), 76px);
  --piece-type: clamp(22px, 5.5vw, 35px);
  --word-type: clamp(23px, 5.5vw, 37px);
  --cut: polygon(
    1% 9%, 4% 7%, 6% 8%, 9% 5%, 13% 7%, 16% 5%, 20% 6%, 23% 4%,
    29% 5%, 32% 3%, 35% 5%, 40% 4%, 45% 6%, 50% 4%, 55% 5%, 60% 3%,
    65% 5%, 71% 4%, 77% 6%, 81% 4%, 86% 6%, 91% 4%, 96% 7%, 99% 6%,
    98% 15%, 100% 25%, 98% 36%, 99% 50%, 98% 62%, 99% 75%, 97% 93%,
    94% 94%, 90% 98%, 86% 95%, 81% 96%, 76% 94%, 69% 96%, 64% 95%,
    59% 97%, 55% 95%, 50% 98%, 45% 96%, 40% 97%, 36% 95%, 31% 97%,
    27% 94%, 22% 96%, 17% 94%, 13% 97%, 9% 94%, 5% 96%, 2% 93%,
    3% 79%, 0% 66%, 2% 54%, 1% 39%, 3% 28%, 1% 16%
  );
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  height: 100dvh;
  background: var(--background);
  color: var(--ink);
  font-family: Yomogi, "Hiragino Maru Gothic ProN", sans-serif;
}

button, a, input { touch-action: manipulation; }

button {
  color: inherit;
  font: inherit;
  padding: 0;
  border: 0;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
  border-radius: 4px;
}

[hidden] { display: none !important; }

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

.sheet {
  width: min(100%, 656px);
  height: 100%;
  margin-inline: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "question" "board" "rack" "action";
  grid-auto-rows: max-content;
  align-content: safe center;
  gap: clamp(10px, 4dvh, 46px);
  padding: calc(50px + env(safe-area-inset-top)) clamp(14px, 6vw, 58px) max(8px, env(safe-area-inset-bottom));
  user-select: none;
  -webkit-user-select: none;
}

.toolbar {
  position: fixed;
  top: max(6px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.rounds { display: flex; gap: 4px; }
.toolbar-actions { display: flex; gap: 4px; }

.settings-trigger, .rounds button {
  min-width: 54px;
  min-height: 38px;
  border: 1px solid #b7aaa2;
  border-radius: 6px;
  background: var(--background);
  cursor: pointer;
}

.rounds button { min-width: 0; padding: 0 8px; white-space: nowrap; }
.settings-trigger { padding: 0 7px; white-space: nowrap; }
.history-trigger { min-width: 38px; color: #8b551e; font-size: 24px; line-height: 1; }
.rounds button[aria-current="step"] { color: #fff; background: #544a45; border-color: #544a45; }
.rounds button:disabled { color: #817872; background: #f3efec; border-color: #e3dcd6; cursor: default; }

@media (max-width: 375px) {
  .toolbar { left: max(6px, env(safe-area-inset-left)); right: max(6px, env(safe-area-inset-right)); gap: 4px; }
  .rounds, .toolbar-actions { gap: 3px; }
  .rounds button, .settings-trigger { min-width: 0; padding-inline: 5px; }
  .history-trigger { min-width: 32px; }
}

.question-area {
  grid-area: question;
  min-height: 2.7em;
  display: grid;
  place-items: center;
  font-size: clamp(20px, min(4.7vw, 6dvh), 36px);
}

.question {
  margin: 0;
  max-width: 100%;
  font-size: inherit;
  font-weight: 400;
  line-height: 1.3;
  text-align: center;
  line-break: strict;
}

.question:focus { outline: none; }

.sheet.has-food {
  grid-template-areas: "question" "food" "board" "rack" "action";
  gap: clamp(6px, 2dvh, 22px);
}
.has-food .question-area { min-height: 0; }

body[data-backdrop="home"] {
  --background: #fffaf0;
  background-color: #f7edda;
  background-image: url("assets/home-floor.jpg");
}

body[data-backdrop="kitchen"] {
  --background: #f8f8f4;
  background-color: #e4e3db;
  background-image: url("assets/kitchen-floor.jpg");
}

body:is([data-backdrop="home"], [data-backdrop="kitchen"]) {
  --red: #8b2d36;
  background-position: center 18%;
  background-repeat: no-repeat;
  background-size: cover;
}

@media (orientation: portrait) {
  body:is([data-backdrop="home"], [data-backdrop="kitchen"]) { background-position: 90% top; }
}

.food-scene {
  grid-area: food;
  --food-height: clamp(60px, 13dvh, 110px);
  position: relative;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: clamp(8px, 5vw, 34px);
  width: 100%;
  height: var(--food-height);
  color: #674339;
  font-size: clamp(8px, min(2vw, 2dvh), 13px);
}

.food-prop { position: relative; flex: none; isolation: isolate; }
.dumplings {
  width: min(clamp(98px, 29vw, 155px), calc(var(--food-height) * 1.28));
  aspect-ratio: 1.28;
}
.oil {
  z-index: 1;
  width: max(44px, calc(var(--food-height) * 0.49));
  height: var(--food-height);
  touch-action: none;
}
.oil:not(:disabled) { cursor: grab; }
.dumplings:not(:disabled) { cursor: pointer; }
.oil[aria-pressed="true"] { outline: 2px dashed #9e4540; outline-offset: 2px; border-radius: 8px; }
.oil.is-pouring { cursor: grabbing; }

.plate, .bottle {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  background-position: center bottom;
  background-size: contain;
}
.plate { background-image: url("assets/gyoza-watercolor.png"); }
.bottle { background-image: url("assets/oil-watercolor.png"); }
.plate b {
  position: absolute;
  display: none;
  top: 59%;
  left: 31%;
  width: 0.43em;
  height: 0.29em;
  border-radius: 50%;
  background: #96361ed9;
  box-shadow: 0.9em -0.22em #af4923d9, 2.45em -0.36em #9c3c22d9,
    2.86em -0.84em #a33b22d9, 3.68em -1.38em #ae4121d9;
}
.is-seasoned .plate b { display: block; }

.is-pouring .bottle::after {
  content: "";
  position: absolute;
  width: 0.4em;
  height: 0.55em;
  top: 8%;
  left: 8%;
  border-radius: 50%;
  background: #b64d2e;
  box-shadow: -0.54em 0.25em #b64d2e;
}

.smoke { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.smoke i { opacity: 0; }
.story-dialog h2 { margin-bottom: 12px; line-height: 1.3; }
.story-actions { margin-top: 10px; }

.board {
  grid-area: board;
  display: grid;
  gap: clamp(6px, 1.8dvh, 18px);
  width: min(100%, 470px);
  margin-inline: auto;
}

.word-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  column-gap: clamp(5px, 2vw, 26px);
}

.row-label {
  font-size: clamp(16px, 4vw, 25px);
  white-space: nowrap;
}

.arrow {
  font-family: sans-serif;
  font-size: clamp(21px, 4.6vw, 35px);
  font-weight: 400;
  color: #534b46;
}

.slot {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  height: var(--piece-height);
  border-radius: 4px;
}

.base {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  white-space: nowrap;
  font-size: var(--word-type);
  line-height: 1;
}

.answer {
  height: 83%;
  max-width: 132px;
  color: #766e69;
  border-bottom: 1px solid #b7aaa2;
  box-shadow: 0 2px 0 #eee8e3;
}

.rack {
  grid-area: rack;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, var(--piece-width)));
  justify-content: center;
  gap: clamp(8px, 3.5vw, 30px);
}

.papers {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.paper {
  position: absolute;
  width: var(--piece-width);
  height: var(--piece-height);
  display: grid;
  place-items: center;
  isolation: isolate;
  font-size: var(--piece-type);
  line-height: 1;
  white-space: nowrap;
  filter: drop-shadow(0 1px 1px #533e2a40) drop-shadow(0 4px 4px #4c372322);
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}

.paper-surface {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  isolation: isolate;
  pointer-events: none;
}

.paper-surface::before, .kana-paper::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--piece-paper, #faf5ec);
  clip-path: var(--cut);
}

.paper-surface::after, .kana-paper::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: repeat url("paper-grain.svg");
  opacity: 0.32;
  clip-path: var(--cut);
}

.paper[data-card="0"] { --tilt: -1.4deg; }
.paper[data-card="1"] { --tilt: 0.6deg; }
.paper[data-card="2"] { --tilt: -0.6deg; }
.paper-restore {
  position: absolute;
  top: 2px;
  right: 3px;
  width: max(34px, 32%);
  height: 30px;
  display: grid;
  place-items: start end;
  padding: 3px 6px;
  color: var(--red);
  font: 18px/1.15 system-ui, sans-serif;
  cursor: pointer;
}
.paper-restore:active { opacity: .62; }
.paper.at-rest .paper-surface { transform: rotate(var(--tilt, 0deg)); }
.paper.is-held {
  filter: drop-shadow(0 6px 5px #4c372343);
  cursor: grabbing;
}

.action-area {
  grid-area: action;
  display: grid;
  justify-items: center;
}

.confirm-slot {
  width: var(--piece-width);
  height: var(--piece-height);
}

.confirm {
  border: 1px solid var(--red-line);
  border-radius: 8px;
  font-size: clamp(21px, 5vw, 31px);
  cursor: pointer;
}

.confirm:active, .action-button:active, .dialog-actions button:active { background: #fbefee; }
.feedback {
  min-height: 1.5em;
  margin: 4px 0 0;
  color: var(--red);
  font-size: clamp(15px, 3vw, 19px);
}

.clear-dialog, .panel {
  width: min(calc(100% - 36px), 330px);
  max-height: calc(100dvh - 24px);
  padding: 28px 22px 24px;
  color: var(--ink);
  background: var(--background);
  border: 1px solid var(--red-line);
  border-radius: 8px;
  text-align: center;
}

.clear-dialog::backdrop, .panel::backdrop { background: #332a2540; }
.clear-dialog h2, .panel h2 { margin: 0 0 16px; font-size: 28px; font-weight: 400; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.dialog-actions button, .action-button {
  display: inline-grid;
  place-items: center;
  min-height: 44px;
  padding: 5px 11px;
  color: inherit;
  border: 1px solid var(--red-line);
  border-radius: 5px;
  cursor: pointer;
  text-decoration: none;
}

.panel { width: min(calc(100% - 28px), 362px); text-align: left; }
.close { position: absolute; top: 6px; right: 8px; width: 42px; height: 42px; cursor: pointer; font-size: 25px; }
.guide p { margin: 0 0 18px; line-height: 1.65; }
.kana-paper {
  position: relative;
  isolation: isolate;
  padding: 28px clamp(13px, 5vw, 22px) 21px;
  filter: drop-shadow(0 1px 1px #533e2a40) drop-shadow(0 4px 4px #4c372322);
}
.kana-paper .paper-restore { top: 4px; right: 7px; }
.kana-paper::after { pointer-events: none; }
.kana-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: clamp(4px, 1.4vw, 7px);
}
.kana-grid span { aspect-ratio: 1; background: #24211f; }
.kana-grid .kana-empty {
  display: grid;
  place-items: center;
  background: transparent;
  font: 600 clamp(0.875rem, 4.2vw, 1.125rem)/1 system-ui, sans-serif;
}
.kana-grid.is-mirrored { transform: scaleX(-1); }
.volume-heading, .volume-row, .record-totals > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.volume-row { margin: 5px 0 10px; }
.volume-row input { flex: 1; min-width: 0; accent-color: var(--red); }
#mute { border-color: #a69690; }
#mute[aria-pressed="true"] { background: #544a45; border-color: #544a45; color: #fff; }
.settings-restart { margin-bottom: 10px; }
.settings-restart:disabled { opacity: .5; cursor: default; }
.setting-links a { display: block; padding: 10px 0; border-top: 1px solid #e7dfda; color: inherit; }
.setting-links small { display: block; margin-top: 4px; color: #625952; text-decoration: none; }
.notice { margin: 8px 0 0; color: #655b56; font-size: 14px; line-height: 1.45; }
.record-totals { margin: 12px 0 0; }
.record-totals > div { min-height: 36px; border-top: 1px solid #e7dfda; }
.record-totals dd { margin: 0; font-variant-numeric: tabular-nums; }
.history-list { display: grid; gap: 8px; }
#record-status { margin-top: 10px; }
#records-retry { margin-top: 10px; }

@media (max-height: 430px) {
  :root {
    --piece-height: clamp(32px, 9.5dvh, 42px);
    --piece-type: clamp(17px, 5.8dvh, 24px);
    --word-type: clamp(18px, 6dvh, 25px);
  }
  .sheet, .sheet.has-food {
    gap: 6px;
    padding-block: calc(43px + env(safe-area-inset-top)) max(5px, env(safe-area-inset-bottom));
  }
  .toolbar { top: max(4px, env(safe-area-inset-top)); }
  .toolbar button { min-height: 32px; }
  .question-area { min-height: 0; font-size: clamp(17px, 5dvh, 22px); }
  .board { gap: 4px; }
  .row-label { font-size: clamp(14px, 5dvh, 19px); }
  .arrow, .confirm { font-size: clamp(18px, 5.7dvh, 23px); }
  .feedback { margin-top: 3px; min-height: 1.3em; font-size: 14px; line-height: 1.3; text-align: center; }
  .food-scene { --food-height: clamp(42px, 12dvh, 55px); gap: 8px; font-size: 7px; }
}

@media (max-height: 430px) and (min-width: 540px) {
  .sheet.has-food {
    grid-template-columns: minmax(0, 1fr) max-content;
    grid-template-areas: "question question" "board food" "rack rack" "action action";
    column-gap: 18px;
  }
  .food-scene { width: auto; align-self: center; }
}

@media (max-height: 325px) and (max-width: 539px) {
  .sheet.has-food {
    grid-template-columns: minmax(0, 1fr) max-content;
    grid-template-areas: "question question" "board board" "rack rack" "action food" "feedback feedback";
  }
  .has-food .action-area { display: contents; }
  .has-food .confirm-slot { grid-area: action; place-self: center; }
  .has-food .feedback { grid-area: feedback; justify-self: center; margin: 0; }
  .food-scene { width: auto; align-self: center; }
}

@media (max-height: 300px) {
  :root { --piece-height: 30px; }
  .sheet, .sheet.has-food {
    gap: 4px;
    padding-block-start: calc(39px + env(safe-area-inset-top));
  }
  .toolbar button { min-height: 30px; }
}

@media (prefers-reduced-motion: no-preference) {
  .paper { transition: filter 150ms; }
  .sheet.is-changing .question { animation: ink-in 200ms ease-out; }
  .is-turning .paper-surface, .kana-paper.is-turning { animation: turn 210ms ease-out; }
  .clear-dialog[open] { animation: ink-in 180ms ease-out; }
  .food-prop.appearing > :not(.smoke) { animation: food-in 360ms 110ms both ease-out; }
  .appearing .smoke i {
    position: absolute;
    width: 3.5em;
    height: 3.5em;
    bottom: 0.4em;
    left: calc(50% - 1.75em);
    border-radius: 50%;
    background: #c5b8ac;
    animation: poof 720ms ease-out both;
  }
  .appearing .smoke i:nth-child(2) { --drift: -2em; animation-delay: 65ms; }
  .appearing .smoke i:nth-child(3) { --drift: 1.8em; animation-delay: 120ms; }
  @keyframes ink-in { from { opacity: 0; } }
  @keyframes turn { from { scale: 1 0.1; } }
  @keyframes food-in { from { opacity: 0; transform: translateY(8px) scale(0.88); } }
  @keyframes poof {
    0% { opacity: 0; transform: scale(.45); }
    22% { opacity: .8; }
    100% { opacity: 0; transform: translate(var(--drift, 0), -3.3em) scale(1.35); }
  }
}

@media (any-pointer: coarse), (hover: none) {
  .paper.long-label .paper-surface {
    font-size: min(var(--piece-type), calc(var(--piece-width) / 4.4));
  }
  .paper > .paper-restore {
    top: -16px;
    right: 2px;
    width: 30px;
    height: min(34px, calc(var(--piece-height) / 2 + 14px));
    padding: 17px 4px 0;
    font-size: 16px;
  }
  .paper, .paper.is-held { filter: none; transition: none; }
  .paper::before {
    content: "";
    position: absolute;
    inset: 0;
    background: #4c372332;
    clip-path: var(--cut);
    transform: translateY(2px);
    pointer-events: none;
  }
  .paper.at-rest::before { transform: translateY(2px) rotate(var(--tilt, 0deg)); }
  .paper.is-held::before { transform: translateY(4px); }
}
