:root {
  color-scheme: light;
  --font-body: "Chiron GoRound TC", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-family: var(--font-body);
  text-align: center;
  --text-scale: 0.9;
  --choice-width-scale: 0.92;
  --choice-height-scale: 0.92;
  --choice-min-font-size: 13px;
  --choice-image-ratio: 2.5006;
  --choice-long-image-ratio: 2.5006;
  --choice-visual-gap: 5px;
  font-size: calc(16px * var(--text-scale));
  color: #65453f;
  background: #ffdee7;
  --viewport-height: 100svh;
  --board-width: min(760px, 64vw, calc(var(--viewport-height) * 0.7));
  --board-height: calc(var(--board-width) * 0.75);
  --choice-reference-width: min(607px, 44vw, calc(var(--viewport-height) * 0.562));
  --layout-gap: min(16px, calc(var(--viewport-height) * 0.015));
}

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

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-width: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  isolation: isolate;
  -webkit-user-select: none;
  user-select: none;
}

input,
textarea,
[contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
}

img {
  -webkit-user-drag: none;
}

.scroll-guide {
  margin: 0;
  padding-inline: 4px;
  font-size: calc(12px * var(--text-scale));
  line-height: 1.6;
  word-break: keep-all;
}

.music-toggle {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 50px);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid #b98f91;
  border-radius: 999px;
  background: #fff8f6;
  color: #65453f;
  box-shadow: 0 3px 10px rgba(101, 69, 63, 0.12);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.music-toggle[aria-pressed="false"] {
  background: #f3e7e5;
}

.music-toggle:focus-visible {
  outline: 3px solid #873e53;
  outline-offset: 3px;
}


.page-background {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: var(--viewport-height);
  overflow: hidden;
  z-index: -1;
  background: #ffdee7;
  pointer-events: none;
  user-select: none;
}

.page-background img {
  position: absolute;
  inset: -2px;
  display: block;
  width: calc(100% + 4px);
  height: calc(100% + 4px);
  object-fit: cover;
  object-position: center;
}

.page-content {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--layout-gap);
  width: 100%;
  height: var(--viewport-height);
  margin-inline: auto;
  padding: 24px;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.board {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  width: var(--board-width);
  height: var(--board-height);
  flex-shrink: 0;
  min-height: 0;
  padding: min(58px, calc(var(--board-width) * 0.095));
  background: url("./image/board.png") center / 100% 100% no-repeat;
  text-align: center;
}

.board-text {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

#welcome-screen {
  width: 100%;
}

#story-screen {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
}

#loading-screen {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  width: 100%;
  height: 100%;
}

.board h1 {
  margin: 0 0 16px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: calc(clamp(22px, 2.4vw, 32px) * var(--text-scale));
  line-height: 1.4;
  word-break: keep-all;
  overflow-wrap: normal;
}

.board h1[tabindex="-1"]:focus {
  outline: none;
}

.board p {
  margin: 0;
  font-size: calc(clamp(15px, 1.4vw, 18px) * var(--text-scale));
  line-height: 1.8;
  white-space: pre-line;
}

.choices {
  display: grid;
  gap: var(--choice-visual-gap);
  width: calc(var(--choice-reference-width) * var(--choice-width-scale));
  min-width: 0;
  flex-shrink: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.choice {
  position: relative;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  height: calc(var(--choice-reference-width) / var(--choice-image-ratio) * var(--choice-height-scale));
  min-height: 0;
  min-width: 0;
  padding: calc(min(22px, calc(var(--choice-reference-width) * 0.034)) * var(--choice-height-scale)) 8%;
  border: 0;
  color: inherit;
  background: url("./image/choice_long.png") center / 100% 100% no-repeat;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.choice-long {
  height: calc(var(--choice-reference-width) / var(--choice-long-image-ratio) * var(--choice-height-scale));
  background-image: url("./image/choice_long.png");
}

#question-choices .choice + .choice {
  margin-top: calc((var(--choice-reference-width) / var(--choice-image-ratio) * var(--choice-height-scale) * -0.22) + var(--choice-visual-gap));
}

#completion-actions {
  gap: 6px;
}

.choice-text {
  display: block;
  width: 100%;
  min-width: 0;
  word-break: keep-all;
  overflow-wrap: normal;
  font-size: calc(clamp(16px, 1.5vw, 20px) * var(--text-scale));
  line-height: 1.5;
}

.choice:active .choice-text {
  font-weight: 700;
}

#welcome-actions .choice-text,
#share-x .choice-text,
#restart-test .choice-text {
  font-weight: 700;
}

#welcome-actions,
#completion-actions {
  width: calc(var(--choice-reference-width) * 0.78);
}

#welcome-actions .choice,
#completion-actions .choice {
  height: calc(var(--choice-reference-width) / var(--choice-image-ratio) * 0.72);
}

#welcome-actions .choice-text {
  white-space: nowrap;
  overflow-wrap: normal;
}

.loading-spinner {
  width: calc(54px * var(--text-scale));
  height: calc(54px * var(--text-scale));
  border: calc(5px * var(--text-scale)) solid #f2c5cf;
  border-top-color: #7b4d45;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loading-text {
  font-weight: 700;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.choice:focus-visible {
  outline: 3px solid #873e53;
  outline-offset: 3px;
  border-radius: 48px;
}

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

.page-content img,
.page-content video {
  max-width: 100%;
  height: auto;
}

button,
input,
textarea,
select {
  font: inherit;
}

.board .eyebrow {
  margin-bottom: 16px;
  font-size: calc(14.4px * var(--text-scale));
  line-height: 1.6;
  text-align: center;
}

.board .welcome-description {
  margin-bottom: 24px;
}

#name-form {
  display: grid;
  gap: 10px;
  width: min(100%, 300px);
  margin-inline: auto;
}

#name-form label {
  font-size: calc(14px * var(--text-scale));
  line-height: 1.5;
}

#player-name {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  border: 1px solid #b98f91;
  border-radius: 12px;
  padding: 12px 16px;
  background: #fffaf8;
  color: inherit;
  font-size: calc(16px * var(--text-scale));
  text-align: center;
}

#player-name::placeholder {
  color: #8e7470;
}

#player-name:focus-visible {
  outline: 3px solid #873e53;
  outline-offset: 3px;
}

#name-hint,
#name-error {
  font-size: calc(12px * var(--text-scale));
  line-height: 1.5;
}

#name-error {
  min-height: 18px;
  color: #a12e49;
}

.board .story-text {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 0 8px;
  margin-right: -18px;
  padding-right: 18px;
  text-align: justify;
  -webkit-overflow-scrolling: touch;
}

#chapter-image,
#result-image {
  display: block;
  width: min(72%, 320px);
  aspect-ratio: 1;
  object-fit: contain;
  flex-shrink: 0;
  margin: 0 auto 12px;
}

#result-eyebrow {
  text-align: center;
}

#result-heading {
  margin: 0 0 14px;
  font-family: var(--font-body);
  font-size: calc(clamp(22px, 2.4vw, 32px) * var(--text-scale));
  line-height: 1.35;
  text-align: center;
}

#result-title {
  margin-bottom: 18px;
  font-weight: 700;
  font-size: calc(clamp(17px, 1.55vw, 21px) * var(--text-scale));
  line-height: 1.6;
  text-align: center;
}

#story-page-text {
  display: block;
  width: 100%;
  white-space: pre-wrap;
  text-align: justify;
}

.result-text {
  display: grid !important;
  gap: 1.2em;
}

#story-page-text p {
  margin: 0;
}

.message-card {
  display: block;
  width: fit-content;
  max-width: 88%;
  margin: 0.4em auto;
  border: 1px solid #e7cbd0;
  border-radius: 16px;
  padding: 0.65em 0.9em;
  background: #fff8f6;
  box-shadow: 0 4px 10px rgba(101, 69, 63, 0.12);
  font-weight: 700;
  text-align: left;
  white-space: normal;
}

.choices-pending {
  visibility: hidden;
}

.story-text::-webkit-scrollbar {
  width: 6px;
}

.story-text::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #c99aa2;
}

@media (max-width: 768px) {
  :root {
    --text-scale: 1;
    --choice-width-scale: 1;
    --choice-height-scale: 0.86;
    --choice-min-font-size: 13px;
    --board-width: min(82vw, 380px);
    --board-height: calc(var(--board-width) * 435 / 329);
    --choice-reference-width: var(--board-width);
    --layout-gap: 16px;
  }

  html,
  body {
    position: fixed;
    inset: 0;
  }

  .page-content {
    justify-content: flex-start;
    padding-top: max(calc(var(--viewport-height) * 0.05), env(safe-area-inset-top));
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  html.keyboard-open .page-content {
    padding-top: max(calc(var(--viewport-height) * 0.05), env(safe-area-inset-top));
  }

  .board {
    flex-shrink: 0;
    max-width: 100%;
    padding: calc(var(--board-width) * 0.085);
    background-image: url("./image/mobile-board.png");
  }

  .board .story-text {
    line-height: 1.85;
    text-align: left;
  }

  #story-page-text {
    text-align: left;
  }

  #chapter-image,
  #result-image {
    width: min(62%, 200px);
    margin-bottom: 18px;
  }

  .music-toggle {
    bottom: calc(12px + env(safe-area-inset-bottom));
    gap: 5px;
    padding: 8px 12px;
    font-size: 11px;
  }

  .choices {
    gap: 5px;
    width: calc(var(--board-width) * var(--choice-width-scale));
    max-width: 100%;
  }

  .choice {
    height: calc(var(--board-width) / var(--choice-image-ratio) * var(--choice-height-scale));
    padding: calc(var(--board-width) * 0.045 * var(--choice-height-scale)) 7%;
  }

  .choice-long {
    height: calc(var(--board-width) / var(--choice-long-image-ratio) * var(--choice-height-scale));
  }

  #question-choices .choice + .choice {
    margin-top: calc((var(--board-width) / var(--choice-image-ratio) * var(--choice-height-scale) * -0.22) + var(--choice-visual-gap));
  }

  #completion-actions {
    gap: 6px;
  }

  .choice-text {
    font-size: calc(clamp(14px, 3.35vw, 17px) * var(--text-scale));
    line-height: 1.34;
  }

  .choice-long .choice-text {
    font-size: calc(clamp(12.5px, 2.95vw, 15px) * var(--text-scale));
    line-height: 1.28;
  }

  #welcome-actions,
  #completion-actions {
    width: calc(var(--board-width) * 0.78);
  }

  #welcome-actions .choice,
  #completion-actions .choice {
    height: calc(var(--board-width) / var(--choice-image-ratio) * 0.68);
  }
}
@media (max-width: 768px) and (max-height: 760px) {
  :root {
    --choice-height-scale: 0.8;
    --choice-min-font-size: 13px;
    --layout-gap: 12px;
  }

  .page-content,
  html.keyboard-open .page-content {
    padding-top: max(calc(var(--viewport-height) * 0.02), env(safe-area-inset-top));
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }

  .choice {
    padding-left: 6%;
    padding-right: 6%;
  }

  .choice-text {
    font-size: calc(clamp(14px, 3.35vw, 17px) * var(--text-scale));
    line-height: 1.4;
  }

  .choice-long .choice-text {
    font-size: calc(clamp(12.5px, 2.95vw, 15px) * var(--text-scale));
    line-height: 1.35;
  }
}


@media (max-height: 700px) {
  .board h1 {
    margin-bottom: 8px;
    font-size: calc(18px * var(--text-scale));
    line-height: 1.3;
  }

  .board .eyebrow {
    margin-bottom: 8px;
    font-size: calc(11px * var(--text-scale));
    line-height: 1.3;
  }

  .board .story-text {
    font-size: calc(14px * var(--text-scale));
    line-height: 1.6;
  }

  .board .welcome-description {
    margin-bottom: 12px;
  }

  #name-form {
    gap: 6px;
  }
}

@media (max-height: 500px) and (min-aspect-ratio: 4/3) {
  :root {
    --board-width: min(607px, 75vw);
    --board-height: calc(var(--viewport-height) * 0.56);
    --choice-reference-width: var(--board-width);
  }

  .page-content {
    padding-top: calc(var(--viewport-height) * 0.1);
  }

  .board {
    padding: 18px 34px;
  }

  .choice {
    height: calc(var(--viewport-height) * 0.105 * var(--choice-height-scale));
    padding: calc(5px * var(--choice-height-scale)) 7%;
  }
}

@media (max-width: 768px) and (max-height: 500px) and (min-aspect-ratio: 4/3) {
  :root {
    --board-width: calc(min(607px, 75vw) * 0.9);
    --board-height: calc(var(--viewport-height) * 0.56 * 0.9);
  }
}
