:root {
  color-scheme: light;
  --ink: #223e35;
  --muted: #596d60;
  --line: #ccd3c4;
  --paper: #f7f8f0;
  --accent: #275f4f;
  --accent-dark: #174538;
  --head-height: 59px;
  --edge: clamp(12px, 2.35vw, 52px);
  font-family: "Noto Sans KR", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; }
h2, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; font-weight: 700; }
button:disabled { cursor: default; opacity: .52; }
button:active:not(:disabled) { translate: 0 1px; }
:focus-visible { outline: 3px solid #287299; outline-offset: 3px; }
[hidden] { display: none !important; }

i[data-icon] { display: inline-flex; align-items: center; justify-content: center; flex: none; }
i[data-icon] svg { display: block; width: 1em; height: 1em; }
.mast {
  height: var(--head-height);
  background: #fdfdf7;
  border-bottom: 1px solid #dbe0d2;
}
.mast-inner {
  height: 100%;
  padding: 0 var(--edge);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.identity, .mast nav, .actions, .dialog-head, .dialog-foot {
  display: flex;
  align-items: center;
}
.identity { gap: 9px; color: inherit; text-decoration: none; }
.identity img { width: 30px; height: 30px; border-radius: 9px; }
.identity strong { font-size: 21px; letter-spacing: -.09em; }
.brand-area {
  margin-left: 5px;
  padding-left: 14px;
  border-left: 1px solid var(--line);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.mast nav, .actions { gap: 8px; }
.tool, .square, .secondary, .primary, .bare {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 10px;
  border: 1px solid #c9d1c0;
  background: #fffef7;
}
.tool { padding: 7px 12px; min-height: 36px; font-size: 14px; }
.tool i, .secondary i { font-size: 18px; }
.tool:hover, .square:hover, .secondary:hover, .bare:hover { background: #e9efe3; }
.primary {
  color: #fffef0;
  background: var(--accent);
  border-color: var(--accent-dark);
  border-bottom-width: 3px;
  min-height: 43px;
  padding: 9px 21px;
}
.primary:hover { background: #1d5142; }
.secondary { min-height: 42px; padding: 8px 14px; }
.square, .bare { padding: 0; aspect-ratio: 1; }
.square { width: 44px; height: 44px; font-size: 21px; }
.bare { width: 35px; height: 35px; background: transparent; border-color: transparent; font-size: 20px; }

.shell {
  height: calc(100vh - var(--head-height));
  height: calc(100svh - var(--head-height));
  min-height: 450px;
  padding: 13px var(--edge) 17px;
}
.play-card {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #bfcab8;
  border-radius: 20px;
  box-shadow: 0 3px 0 #3b534011;
  background: #f9faf0;
}
.stage {
  position: relative;
  isolation: isolate;
  flex: 1 1 auto;
  min-height: 210px;
  overflow: hidden;
  background: #e0e6d8;
}

#scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#scene > canvas { display: block; width: 100%; height: 100%; }
#scene:focus-visible { outline-offset: -5px; }
#scene[data-hovered="true"] { cursor: grab; }
.stage[data-phase="dragging"] #scene { cursor: grabbing; }
.keyboard-help {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 12px;
  translate: -50% 0;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 7px 12px;
  border-radius: 12px;
  background: #fffef3ed;
  color: var(--ink);
  font-size: 14px;
  text-align: center;
  pointer-events: none;
}
.stage:not(:has(#scene:focus-visible)) .keyboard-help,
.stage:is([data-phase="ready"], [data-phase="intro"]) .keyboard-help {
  clip-path: inset(50%);
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
}
.stage-meta {
  position: absolute;
  z-index: 2;
  inset: clamp(12px, 1.7vw, 28px) clamp(14px, 1.9vw, 32px) auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}
.status {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 13px;
  border-radius: 20px;
  background: #fffef1ed;
  border: 1px solid #c1cdb5;
  color: #3d5847;
  font-size: clamp(13px, 1vw, 17px);
  font-weight: 700;
  line-height: 1.28;
}
.status { gap: 8px; }
.status b { width: 8px; height: 8px; background: #63966f; border-radius: 50%; }
.control-deck {
  flex: none;
  display: grid;
  grid-template-columns: minmax(130px, 1fr) auto minmax(130px, 1fr);
  align-items: center;
  gap: 14px;
  min-height: 84px;
  padding: 13px clamp(14px, 2vw, 34px);
  border-top: 1px solid #c6cbb4;
  background: #fffdf2;
}
.turn-controls { grid-column: 2; min-width: 0; display: flex; align-items: center; justify-content: center; }
.actions { grid-column: 3; justify-self: end; }
#drawBtn {
  min-width: clamp(170px, 16vw, 255px); min-height: 51px;
  border-radius: 13px; font-size: clamp(17px, 1.35vw, 22px);
}
.gesture-hint {
  color: #385748;
  font-weight: 650;
  font-size: clamp(15px, 1.15vw, 19px);
  text-align: center;
  line-height: 1.4;
  word-break: keep-all;
}

.result {
  position: absolute;
  z-index: 3;
  top: clamp(68px, 15%, 180px);
  right: clamp(18px, 3%, 60px);
  width: clamp(172px, 20vw, 325px);
  max-height: 58%;
  overflow: auto;
  text-align: center;
  overflow-wrap: anywhere;
  border: 1px solid #a6b9a4;
  border-top: 5px solid #548268;
  border-radius: 16px;
  padding: 14px 16px 17px;
  background: #fffef3f5;
  box-shadow: 0 5px 18px #415c3e1a;
}
.result.is-marked { border-top-color: #417b88; }
.tip-detail {
  position: relative;
  width: clamp(70px, 5.8vw, 100px);
  aspect-ratio: 1;
  overflow: hidden;
  margin: 0 auto 8px;
  border: 1px solid #d5d8c7;
  border-radius: 50%;
  background: radial-gradient(circle at 37% 28%, #fffef0, #e6ead6);
}
.tip-detail i {
  position: absolute;
  top: 48%;
  right: 16%;
  width: 102%;
  height: 24%;
  border-radius: 0 24% 28% 0 / 0 42% 42% 0;
  transform: rotate(31deg);
  transform-origin: right center;
  background: linear-gradient(180deg, #c19457 0%, #f3d299 26%, #e6bd80 51%, #d3a468 72%, #a87942 100%);
  box-shadow: 0 4px 5px #54462338;
  overflow: hidden;
}
.is-marked .tip-detail i::after {
  content: "";
  position: absolute;
  inset: 0 0 0 48%;
  background:
    linear-gradient(180deg, #0002, #fff4 25%, transparent 50%, #0003),
    linear-gradient(90deg, transparent 15%, #ffefd0 15% 20%, transparent 20% 33%, #ffefd0 33% 38%, transparent 38%),
    var(--tip-color);
}
.result-copy { min-width: 0; }
.result-meta { display: flex; align-items: center; justify-content: center; gap: 7px; font-size: 14px; color: var(--muted); }
.result strong { display: block; margin: 4px 0; font-size: clamp(30px, 3.1vw, 55px); line-height: 1.24; letter-spacing: -.055em; }
.result p { white-space: pre-wrap; font-size: clamp(15px, 1.3vw, 22px); line-height: 1.5; }
.result.is-marked strong { color: #306575; }
.pause-cover { position: absolute; z-index: 6; inset: 0; display: grid; place-items: center; background: #233e3480; }
.pause-cover > div {
  display: grid; justify-items: center; gap: 12px;
  padding: 23px 30px; border: 1px solid #b5c5ae; border-radius: 17px; background: #fffdf0; font-size: 21px;
}

.quick-fields { display: grid; gap: 9px; }
.step-line, .switch-line, .color-field { display: flex; justify-content: space-between; gap: 12px; align-items: center; font-size: 15px; font-weight: 650; }
.stepper { display: flex; align-items: center; border: 1px solid #c3cdbb; border-radius: 8px; overflow: hidden; background: #fffff8; }
.stepper input { width: 36px; text-align: center; font-weight: 750; border: 0; background: transparent; appearance: textfield; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button { appearance: none; }
.stepper button { width: 34px; height: 33px; border: 0; background: transparent; font-size: 18px; }
.stepper button:hover:not(:disabled) { background: #e8efdf; }
.stepper :focus-visible { outline-offset: -3px; }
.switch { width: 42px; height: 25px; flex: none; appearance: none; position: relative; margin: 0; border: 1px solid #a3b29b; border-radius: 20px; background: #d1d8c9; cursor: pointer; }
.switch::before { content: ""; display: block; width: 19px; height: 19px; position: absolute; top: 2px; left: 2px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px #32432e38; }
.switch:checked { background: var(--accent); border-color: var(--accent); }
.switch:checked::before { left: 19px; }
.hint { font-size: 14px; color: #41614e; background: #ebf2e5; padding: 7px 10px; border-radius: 6px; }

dialog {
  color: var(--ink);
  background: #fbfcf2;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  width: min(540px,calc(100% - 26px));
  box-shadow: 0 18px 90px #38281538;
  max-height: 88dvh;
}

dialog::backdrop {
  background: #233c3168;
}

dialog[open],dialog form {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

dialog form {
  min-height: 0;
}

.small-dialog {
  width: min(408px,calc(100% - 26px));
}

.dialog-head,.dialog-foot {
  padding: 15px 22px;
  gap: 10px;
  flex: none;
}

.dialog-head {
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  font-size: 21px;
  letter-spacing: -.055em;
}

.dialog-body {
  padding: 20px 23px;
  overflow: auto;
  overscroll-behavior: contain;
}

.dialog-body>p {
  font-size: 15px;
  line-height: 1.6;
}

.dialog-body fieldset {
  padding: 0;
  border: 0;
  margin: 0 0 22px;
  min-width: 0;
  display: grid;
  gap: 11px;
}

.dialog-body fieldset:last-of-type {
  margin: 0;
}

.dialog-body legend {
  padding: 0 0 9px;
  color: var(--accent);
  font-size: 16px;
  font-weight: 750;
}

.field {
  display: grid;
  gap: 5px;
  font-size: 14px;
  font-weight: 650;
}

.field input,.field textarea,.field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: #fffefb;
  border-radius: 7px;
  font-size: 15px;
}

.field select {
  appearance: none;
  background: #fffefa url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='%23735642' stroke-width='2'/%3E%3C/svg%3E") right 12px center/15px no-repeat;
}

.field textarea {
  resize: vertical;
}

.color-field input {
  width: 48px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
}

.dialog-foot {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
}

.secondary {
  min-height: 42px;
  padding: 8px 20px;
  border-radius: 8px;
  background: white;
}

.sound-controls {
  display: grid;
  gap: 24px;
}

.sound-controls .switch-line {
  font-size: 17px;
}

.volume-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  margin-top: 10px;
}

.volume-line input {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
}

.volume-line output {
  min-width: 36px;
  text-align: right;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  translate: -50% 0;
  background: var(--ink);
  color: white;
  border-radius: 12px;
  padding: 12px 18px;
  z-index: 20;
  font-size: 14px;
  max-width: 95%;
  width: max-content;
}


html:fullscreen, body.expanded { background: var(--paper); }
body.expanded { position: fixed; inset: 0; z-index: 10; overflow: auto; overscroll-behavior: contain; }
:is(html:fullscreen body, body.expanded) { --edge: 3px; --head-height: 43px; }
:is(html:fullscreen body, body.expanded) .shell { padding-top: 2px; padding-bottom: 2px; }
:is(html:fullscreen body, body.expanded) .play-card { border-radius: 9px; }

@media (max-width: 900px) {
  .control-deck { grid-template-columns: auto minmax(0, 1fr) auto; padding: 10px 12px; gap: 9px; min-height: 70px; }
  .turn-controls { grid-column: 1 / 3; }
}
@media (max-width: 700px) {
  :root { --head-height: 52px; --edge: 9px; }
  .shell { padding-top: 7px; padding-bottom: 9px; }
  .play-card { border-radius: 15px; }
  .mast-inner { padding: 0 13px; }
  .mast nav { gap: 5px; }
  .identity { gap: 6px; }
  .identity strong { font-size: 19px; }
  .identity img { width: 27px; height: 27px; }
  .brand-area { margin-left: 2px; padding-left: 9px; font-size: 12px; }
  .tool { min-width: 35px; padding: 7px; }
  .tool > span { display: none; }
  .status { min-height: 27px; padding: 4px 9px; font-size: 12px; }
  .actions { gap: 5px; }
  .square { width: 39px; height: 39px; font-size: 18px; }
  .actions .secondary { padding: 7px; font-size: 13px; gap: 5px; min-height: 38px; }
  #drawBtn { min-width: 130px; padding: 9px 12px; min-height: 45px; font-size: 16px; }
  .gesture-hint { font-size: 14px; }
  .control-deck { min-height: 78px; }
  .control-deck:has(.actions > :not([hidden])) .turn-controls { justify-content: flex-start; }
  .control-deck:not(:has(.actions > :not([hidden]))) .turn-controls { grid-column: 1 / -1; grid-row: 1; }
  .actions { grid-row: 1; }
  .result { position: relative; top: auto; right: auto; width: auto; max-height: 26svh; flex: none; padding: 6px 13px; border: 0; border-top: 1px solid var(--line); border-radius: 0; box-shadow: none; }
  .result strong { margin: 0; font-size: 25px; }
  .result { display: flex; justify-content: center; align-items: center; gap: 12px; }
  .tip-detail { flex: none; width: 48px; margin: 0; }
  .result-meta, .result p { font-size: 13px; }
  .dialog-head, .dialog-foot, .dialog-body { padding-inline: 16px; }
}
@media (max-width: 370px) {
  .identity strong { display: none; }
  .brand-area { margin: 0; padding: 0; border: 0; }
  .edit-grid { grid-template-columns: 1fr; }
  .actions .secondary { gap: 2px; padding-inline: 5px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  :root, :is(html:fullscreen body, body.expanded) { --head-height: 39px; --edge: 6px; }
  .shell { min-height: 270px; padding-block: 3px; }
  .play-card { border-radius: 11px; }
  .stage { min-height: 138px; }
  .control-deck { min-height: 52px; padding-block: 4px; }
  #drawBtn { min-height: 39px; }
  .stage-meta { inset: 7px 10px auto; }
}
