:root {
  --ink: #21180f;
  --brown: #5b321c;
  --deep-brown: #2a1b12;
  --cream: #f4e3bf;
  --paper: #f9edcf;
  --teal: #2f7772;
  --mustard: #dfa631;
  --orange: #c95f25;
  --shadow: rgba(26, 15, 8, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  background: #221911;
  font-family:
    "Hiragino Maru Gothic ProN",
    "Yu Gothic",
    "Meiryo",
    system-ui,
    sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.stage {
  display: grid;
  place-items: center;
  min-height: 100svh;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

.game-shell {
  position: relative;
  width: min(calc(100vw - 16px), 440px, calc((100svh - 16px) * 9 / 16));
  aspect-ratio: 9 / 16;
  overflow: hidden;
  isolation: isolate;
  background: var(--teal);
  border: 4px solid #f0dfb7;
  box-shadow: 0 22px 60px var(--shadow);
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.screen[hidden] {
  display: none;
}

.screen-bg {
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}

.screen-start,
.screen-fail,
.screen-clear {
  background-size: 100% 100%;
}

.screen-bg::before {
  position: absolute;
  inset: 0;
  z-index: 0;
  content: "";
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 244, 210, 0.04) 0,
      rgba(255, 244, 210, 0.04) 1px,
      transparent 1px,
      transparent 4px
    );
  mix-blend-mode: multiply;
  pointer-events: none;
}

.screen-bg > * {
  position: relative;
  z-index: 1;
}

.screen-start {
  justify-content: flex-end;
  align-items: center;
  gap: 0.38rem;
  padding: 0 6.5% 3.8%;
  background-image: url("assets/images/start_star_new.jpeg");
}

.screen-game {
  justify-content: space-between;
  padding: calc(9.2% + 30px) 5.6% 6.1%;
  background-image: url("assets/images/game_bg.png");
}

.screen-fail {
  justify-content: flex-end;
  align-items: center;
  padding: 0 7% 6.4%;
  background-image: url("assets/images/fail.png");
}

.screen-clear {
  justify-content: flex-end;
  align-items: center;
  padding: 0 5.4% 4.8%;
  background-image: url("assets/images/clear.png");
}

.screen-ranking {
  justify-content: center;
  align-items: center;
  gap: 0.92rem;
  padding: 3.8% 5.2% 4.3%;
  background-image: url("assets/images/game_bg.png");
}

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

.retro-button,
.choice-button {
  min-height: 60px;
  border: 4px solid var(--deep-brown);
  color: var(--ink);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow:
    inset 0 0 0 3px rgba(255, 243, 207, 0.7),
    0 8px 0 #2b1c12,
    0 12px 18px rgba(21, 12, 7, 0.28);
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    filter 120ms ease;
}

.retro-button:active,
.retro-button.is-tapped,
.choice-button:active,
.choice-button.is-tapped {
  transform: translateY(6px) scale(0.985);
  box-shadow:
    inset 0 0 0 3px rgba(255, 243, 207, 0.65),
    0 2px 0 #2b1c12,
    0 6px 12px rgba(21, 12, 7, 0.22);
}

.retro-button:focus-visible,
.choice-button:focus-visible {
  outline: 4px solid #fff2bd;
  outline-offset: 4px;
}

.start-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.3rem;
  width: min(66%, 282px);
}

.start-button,
.replay-button,
.secondary-button {
  width: min(84%, 360px);
  min-height: clamp(64px, 10.6svh, 92px);
  padding: 0.35em 0.75em 0.42em;
  border-radius: 28px;
  background: var(--paper);
  font-size: clamp(2.2rem, 10vw, 3.2rem);
  text-shadow:
    2px 2px 0 rgba(255, 245, 213, 0.9),
    -1px -1px 0 rgba(255, 245, 213, 0.55);
}

.start-actions .start-button,
.start-actions .secondary-button {
  width: 100%;
  min-height: clamp(34px, 5.3svh, 44px);
  border-width: 3px;
  border-radius: 14px;
  padding: 0.15em 0.7em 0.24em;
  box-shadow:
    inset 0 0 0 2px rgba(255, 243, 207, 0.65),
    0 5px 0 #2b1c12,
    0 8px 12px rgba(21, 12, 7, 0.22);
}

.start-actions .start-button {
  font-size: clamp(1.22rem, 5.7vw, 1.68rem);
}

.secondary-button {
  background: var(--mustard);
  font-size: clamp(0.82rem, 3.9vw, 1.1rem);
}

.replay-button {
  background: var(--mustard);
  font-size: clamp(2rem, 9.2vw, 3.05rem);
}

.screen-fail .replay-button {
  background: var(--orange);
  color: #fff0c8;
  text-shadow: 2px 2px 0 var(--deep-brown);
}

.quit-button {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 5;
  min-height: 34px;
  padding: 0.22rem 0.52rem 0.28rem;
  border: 3px solid var(--deep-brown);
  border-radius: 999px;
  background: rgba(249, 237, 207, 0.92);
  color: var(--deep-brown);
  font-size: clamp(0.72rem, 3.4vw, 0.9rem);
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(42, 27, 18, 0.92);
}

.quit-button:active,
.quit-button.is-tapped {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(42, 27, 18, 0.92);
}

.game-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 0.72rem 0.85rem 0.68rem;
  border: 3px solid var(--deep-brown);
  border-radius: 8px;
  background: rgba(248, 226, 181, 0.9);
  box-shadow:
    inset 0 0 0 2px rgba(94, 54, 28, 0.18),
    0 6px 0 rgba(42, 27, 18, 0.9);
}

.game-header h1,
.question-count,
.food-name,
.feedback,
.end-copy h2,
.end-copy p {
  margin: 0;
}

.game-header h1 {
  flex: 1 1 auto;
  font-size: clamp(1.35rem, 5.8vw, 2rem);
  line-height: 1;
  white-space: nowrap;
  color: var(--orange);
  text-shadow:
    2px 2px 0 var(--deep-brown),
    -1px -1px 0 var(--paper);
}

.question-count {
  flex: 0 0 auto;
  align-self: center;
  padding: 0.36rem 0.56rem;
  border: 2px solid var(--brown);
  border-radius: 6px;
  background: var(--teal);
  color: #fff6d6;
  font-size: clamp(0.95rem, 4.4vw, 1.3rem);
  font-weight: 900;
  line-height: 1;
}

.game-stats {
  display: grid;
  gap: 0.35rem;
  justify-items: end;
}

.timer-display {
  min-width: 5.1rem;
  margin: 0;
  padding: 0.32rem 0.5rem;
  border: 2px solid var(--brown);
  border-radius: 6px;
  background: #1c1915;
  color: #f7d36a;
  font-family: "Courier New", ui-monospace, monospace;
  font-size: clamp(0.95rem, 4.4vw, 1.32rem);
  font-weight: 900;
  line-height: 1;
  text-align: right;
  text-shadow: 0 0 6px rgba(247, 211, 106, 0.65);
}

.food-area {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0.75rem;
  min-height: 0;
  padding-bottom: 2%;
}

.food-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: min(96%, 374px);
  aspect-ratio: 420 / 366;
}

.food-frame::before {
  position: absolute;
  inset: 7% 4% 3%;
  z-index: 0;
  content: "";
  border-radius: 10px;
  background: rgba(42, 27, 18, 0.58);
  filter: blur(4px);
  transform: translateY(10px) scale(0.98);
  pointer-events: none;
}

.food-frame img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  filter: saturate(0.98) contrast(1.03);
  transition: opacity 80ms ease-out;
  will-change: transform;
}

.food-frame img.is-loaded {
  opacity: 1;
}

.food-frame img.is-missing {
  display: none;
  opacity: 0;
}

.image-fallback {
  margin: 0;
  color: var(--brown);
  font-size: clamp(1.1rem, 5vw, 1.6rem);
  font-weight: 900;
}

.food-name {
  max-width: 92%;
  padding: 0.42rem 1.1rem 0.48rem;
  border: 4px solid var(--deep-brown);
  border-radius: 8px;
  background: var(--mustard);
  box-shadow:
    inset 0 0 0 3px rgba(255, 241, 198, 0.55),
    0 7px 0 rgba(42, 27, 18, 0.9);
  font-size: clamp(1.8rem, 8.8vw, 2.75rem);
  font-weight: 900;
  line-height: 1.08;
  text-align: center;
  white-space: nowrap;
  text-shadow: 2px 2px 0 rgba(255, 239, 190, 0.5);
}

.feedback {
  position: absolute;
  top: 40%;
  left: 50%;
  z-index: 3;
  padding: 0.45rem 1.15rem 0.58rem;
  border: 4px solid var(--deep-brown);
  border-radius: 8px;
  background: #fff2bd;
  color: var(--orange);
  box-shadow: 0 9px 0 rgba(42, 27, 18, 0.9);
  font-size: clamp(1.9rem, 9.5vw, 3.1rem);
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  text-shadow: 2px 2px 0 var(--deep-brown);
  transform: translate(-50%, -50%) rotate(-3deg);
  animation: pop 190ms ease both;
}

.choice-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  width: 100%;
}

.choice-button {
  min-width: 0;
  min-height: clamp(68px, 12svh, 94px);
  padding: 0.4rem 0.2rem 0.5rem;
  border-radius: 22px;
  font-size: clamp(2.1rem, 11vw, 3.7rem);
}

.tare-button {
  background: #5a2e20;
  color: #fff0c8;
  text-shadow: 2px 2px 0 #1d120b;
}

.sauce-button {
  background: #f1dcad;
  color: var(--ink);
  text-shadow: 2px 2px 0 rgba(255, 250, 224, 0.8);
}

.choice-button:disabled {
  cursor: default;
  filter: saturate(0.8);
}

.end-copy {
  width: min(92%, 360px);
  margin-bottom: 1rem;
  padding: 0.88rem 0.9rem 0.95rem;
  border: 4px solid var(--deep-brown);
  border-radius: 8px;
  background: rgba(249, 237, 207, 0.92);
  box-shadow:
    inset 0 0 0 3px rgba(95, 53, 29, 0.16),
    0 8px 0 rgba(42, 27, 18, 0.95);
  text-align: center;
}

.end-copy h2 {
  font-size: clamp(2rem, 10vw, 3.35rem);
  line-height: 1.02;
  text-shadow: 2px 2px 0 rgba(255, 244, 209, 0.75);
}

.end-copy p {
  margin-top: 0.32rem;
  font-size: clamp(1.1rem, 5.8vw, 1.65rem);
  font-weight: 900;
  line-height: 1.16;
}

.fail-copy h2,
.fail-copy p:first-of-type {
  color: var(--orange);
}

.clear-copy h2 {
  color: var(--orange);
}

.leaderboard-panel,
.arcade-board,
.ranking-board {
  border: 4px solid #1a130d;
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.03), transparent),
    #1c1915;
  color: #f7d36a;
  box-shadow:
    inset 0 0 0 3px rgba(247, 211, 106, 0.14),
    0 7px 0 rgba(42, 27, 18, 0.96);
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 900;
  text-shadow: 0 0 7px rgba(247, 211, 106, 0.72);
}

.leaderboard-panel h2,
.arcade-board h2,
.ranking-board h2,
.result-label,
.result-time,
.result-rank-badge,
.result-message,
.save-confirm p,
.name-form label,
.form-message {
  margin: 0;
}

.start-leaderboard {
  position: absolute;
  top: 35.46%;
  left: 50.2%;
  width: 42.35%;
  height: 8.25%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 0.2rem 0.42rem 0.22rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  transform: none;
  transform-origin: center;
}

.start-leaderboard h2 {
  position: relative;
  top: -7px;
  margin: 0 0 0.1rem;
  color: #e65e2b;
  font-size: clamp(0.82rem, 3.8vw, 1.04rem);
  line-height: 1;
  text-align: center;
  text-shadow:
    2px 2px 0 #000,
    0 0 8px rgba(230, 94, 43, 0.7);
}

.start-leaderboard .rank-row,
.start-leaderboard .rank-empty {
  grid-template-columns: 1.42em minmax(0, 1fr) 3.18em;
  gap: 0.12rem;
  min-height: 0.88em;
  color: #fff0a9;
  font-size: clamp(0.49rem, 2.2vw, 0.62rem);
  line-height: 0.96;
  letter-spacing: 0;
}

.start-leaderboard .rank-list {
  align-content: start;
  gap: 0.08rem;
  min-height: 0;
  transform: none;
  transform-origin: center top;
}

.rank-list {
  display: grid;
  gap: 0.22rem;
  padding: 0;
  margin: 0;
  list-style: none;
}

.rank-row,
.rank-empty {
  display: grid;
  grid-template-columns: 2.35em 1fr 4.8em;
  gap: 0.38rem;
  align-items: baseline;
  min-height: 1.15em;
  font-size: clamp(0.78rem, 3.6vw, 1.05rem);
  line-height: 1;
}

.rank-empty {
  display: block;
  color: rgba(247, 211, 106, 0.72);
  text-align: center;
}

.rank-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-time {
  text-align: right;
}

.arcade-board {
  display: grid;
  gap: 0.38rem;
  width: min(96%, 382px);
  max-height: 58%;
  padding: 0.58rem 0.58rem 0.62rem;
}

.result-label {
  color: #e65e2b;
  font-size: clamp(0.92rem, 4vw, 1.12rem);
  line-height: 1;
  text-align: center;
  text-shadow:
    2px 2px 0 #000,
    0 0 7px rgba(230, 94, 43, 0.7);
}

.result-time {
  color: #fff1ad;
  font-size: clamp(1.42rem, 7vw, 2.05rem);
  line-height: 1;
  text-align: center;
}

.result-rank-badge {
  color: #e65e2b;
  font-size: clamp(1.18rem, 5.8vw, 1.72rem);
  line-height: 1;
  text-align: center;
  text-shadow:
    2px 2px 0 #000,
    0 0 8px rgba(230, 94, 43, 0.72);
}

.result-message {
  min-height: 1em;
  color: #fff1ad;
  font-size: clamp(0.68rem, 3.2vw, 0.9rem);
  line-height: 1;
  text-align: center;
}

.save-confirm,
.name-form {
  display: grid;
  gap: 0.38rem;
  padding: 0.46rem;
  border: 2px solid rgba(247, 211, 106, 0.55);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.28);
  text-align: center;
}

.save-confirm[hidden],
.name-form[hidden],
.post-result-menu[hidden] {
  display: none;
}

.save-title {
  color: #e65e2b;
  font-size: clamp(0.92rem, 4.3vw, 1.22rem);
}

.save-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.mini-button {
  min-height: 38px;
  padding: 0.26rem 0.42rem 0.31rem;
  border: 3px solid #1a130d;
  border-radius: 6px;
  background: var(--mustard);
  color: var(--ink);
  font-family: inherit;
  font-weight: 900;
  cursor: pointer;
  box-shadow:
    inset 0 0 0 2px rgba(255, 241, 198, 0.45),
    0 4px 0 #000;
}

.mini-button:active,
.mini-button.is-tapped {
  transform: translateY(3px);
  box-shadow:
    inset 0 0 0 2px rgba(255, 241, 198, 0.45),
    0 1px 0 #000;
}

.name-form label {
  color: #fff1ad;
  font-size: 1rem;
}

.name-form input {
  width: 100%;
  min-height: 44px;
  border: 3px solid rgba(247, 211, 106, 0.8);
  border-radius: 6px;
  background: #f7e6b6;
  color: #1c1915;
  font-family: inherit;
  font-size: clamp(1.15rem, 5vw, 1.45rem);
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.form-message {
  min-height: 1.1em;
  color: #ff8a53;
  font-size: 0.78rem;
  line-height: 1.15;
}

.result-leaderboard {
  padding: 0.42rem 0.48rem;
  border-width: 2px;
  box-shadow: inset 0 0 0 2px rgba(247, 211, 106, 0.12);
}

.post-result-menu {
  display: grid;
  gap: 0.42rem;
}

.result-leaderboard h2 {
  margin: 0 0 0.32rem;
  color: #e65e2b;
  font-size: clamp(0.92rem, 4.3vw, 1.18rem);
  line-height: 1;
  text-align: center;
  text-shadow:
    2px 2px 0 #000,
    0 0 7px rgba(230, 94, 43, 0.7);
}

.result-leaderboard .rank-list {
  gap: 0.09rem;
}

.result-leaderboard .rank-row,
.result-leaderboard .rank-empty {
  grid-template-columns: 1.95em 1fr 4.05em;
  gap: 0.24rem;
  min-height: 0.92em;
  font-size: clamp(0.5rem, 2.25vw, 0.64rem);
  line-height: 0.95;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.42rem;
}

.result-actions .bgm-button {
  grid-column: 1 / -1;
  min-height: 34px;
  font-size: clamp(0.72rem, 3.2vw, 0.88rem);
}

.ranking-board {
  display: grid;
  grid-template-rows: auto auto 42px;
  gap: 0.58rem;
  width: min(92%, 378px);
  height: auto;
  max-height: calc(100% - 86px);
  padding: 0.78rem 0.86rem 0.74rem;
}

.ranking-board h2 {
  color: #e65e2b;
  font-size: clamp(1.16rem, 5.35vw, 1.56rem);
  line-height: 1;
  text-align: center;
  text-shadow:
    2px 2px 0 #000,
    0 0 8px rgba(230, 94, 43, 0.72);
}

.full-rank-list {
  grid-template-rows: none;
  grid-auto-flow: row;
  grid-auto-columns: auto;
  column-gap: 0;
  row-gap: 0.08rem;
  align-content: start;
  min-height: 0;
  overflow: hidden;
  transform: scaleX(0.88);
  transform-origin: center top;
}

.full-rank-list .rank-row,
.full-rank-list .rank-empty {
  grid-template-columns: 2.55em minmax(0, 1fr) 3.65em;
  gap: 0.16rem;
  min-height: 1em;
  font-size: 0.86rem;
  line-height: 0.96;
  letter-spacing: -0.04em;
}

.ranking-pager {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 0.45rem;
  align-items: center;
  align-self: end;
}

.pager-button {
  display: grid;
  place-items: center;
  min-height: 32px;
  border: 3px solid #1a130d;
  border-radius: 8px;
  background: var(--mustard);
  color: var(--ink);
  font-family: inherit;
  font-size: 1.2rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  box-shadow:
    inset 0 0 0 2px rgba(255, 241, 198, 0.42),
    0 4px 0 #000;
}

.pager-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.pager-button:active:not(:disabled),
.pager-button.is-tapped {
  transform: translateY(3px);
  box-shadow:
    inset 0 0 0 2px rgba(255, 241, 198, 0.42),
    0 1px 0 #000;
}

.ranking-page-label {
  margin: 0;
  color: #fff1ad;
  font-family: "Courier New", ui-monospace, monospace;
  font-size: clamp(0.78rem, 3.5vw, 1rem);
  font-weight: 900;
  line-height: 1;
  text-align: center;
}

.ranking-back-button {
  width: min(52%, 230px);
  min-height: 44px;
  font-size: clamp(1.2rem, 5.6vw, 1.6rem);
}

.is-changing .food-frame img,
.is-changing .food-name {
  animation: swap-in 140ms ease both;
}

@keyframes pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.72) rotate(-7deg);
  }

  55% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08) rotate(-2deg);
  }

  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(-3deg);
  }
}

@keyframes swap-in {
  from {
    opacity: 1;
    transform: translateY(4px) scale(0.992);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-height: 620px) {
  .screen-game {
    padding-top: calc(8.4% + 24px);
    padding-bottom: 5%;
  }

  .food-area {
    gap: 0.5rem;
    padding-bottom: 2%;
  }

  .food-frame {
    width: min(82%, 330px);
  }

  .end-copy {
    margin-bottom: 0.65rem;
  }
}
