* { box-sizing: border-box; }

:root {
  color-scheme: light;
  font-family: "Noto Sans Thai", system-ui, sans-serif;
  background: #f7f2ff;
  color: #302345;
  --ink: #302345;
  --muted: #605573;
  --accent: #593787;
  --accent-hover: #49296f;
}

[hidden], #status:empty { display: none !important; }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 85% 12%, #e5f5ee 0%, transparent 42%),
    radial-gradient(ellipse at 13% 83%, #f9e8f1 0%, transparent 42%),
    linear-gradient(145deg, #fcf9ff, #eeebfb);
}

main {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(280px, 480px) minmax(290px, 470px);
  align-items: center;
  justify-content: center;
  gap: clamp(2rem, 7vw, 7rem);
  --page-pad: clamp(1.25rem, 5vw, 4rem);
  padding: max(var(--page-pad), env(safe-area-inset-top)) max(var(--page-pad), env(safe-area-inset-right))
    max(var(--page-pad), env(safe-area-inset-bottom)) max(var(--page-pad), env(safe-area-inset-left));
}

.setup { min-width: 0; container-type: inline-size; }
.edition {
  display: inline-flex;
  margin: 0 0 1rem;
  padding: 0.32rem 0.85rem;
  border: 1px solid #d8caed;
  border-radius: 2rem;
  background: #eee4ff;
  color: #54347f;
  font-size: 0.88rem;
  font-weight: 700;
}
h1 {
  margin: 0;
  font: 800 clamp(2.3rem, 15.5cqw, 4.85rem)/0.96 "DM Sans", system-ui, sans-serif;
  letter-spacing: -0.075em;
  color: var(--ink);
}
h1 span { display: inline-block; color: #7756ac; }
.intro { max-width: 36ch; font-size: 1.05rem; line-height: 1.85; margin: 1.3rem 0 1.55rem; color: var(--muted); }

.file-card {
  position: relative;
  min-width: 0;
  padding: 1.1rem;
  max-width: 365px;
  background: #fffdfef2;
  border: 1px solid #e2d7ef;
  border-radius: 1.2rem;
  box-shadow: 0 8px 26px #4f327d10;
}

.file-button, button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  padding: 0.55rem 1.15rem;
  border-radius: 0.8rem;
  border: 0;
  font: 700 1rem/1.4 "Noto Sans Thai", sans-serif;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
}

.file-button {
  width: 100%;
  min-height: 54px;
  gap: 0.64rem;
  box-shadow: 0 3px 0 #3d225f;
}
.file-icon {
  width: 14px;
  height: 17px;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  position: relative;
}
.file-icon::after {
  content: "";
  position: absolute;
  height: 1.5px;
  width: 6px;
  bottom: 4px;
  left: 2.5px;
  background: currentColor;
  box-shadow: 0 -3px currentColor;
}
.file-button:hover, button:hover { background: var(--accent-hover); }
.file-card:focus-within .file-button, button:focus-visible {
  outline: 3px solid #895cbd;
  outline-offset: 4px;
}

#rom { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; }
.file-card.busy .file-button { opacity: 0.62; cursor: wait; }
#file-help, .privacy, #session { font-size: 0.875rem; color: var(--muted); line-height: 1.7; }
#file-help { margin: 0.85rem 0 0; text-align: center; }
#status { margin: 0.8rem 0 0; font-size: 0.94rem; overflow-wrap: anywhere; }
#status.error { color: #9c294c; }
.privacy { margin: 0.8rem 0 0; }
#session button { background: #f0e6fc; color: #513279; box-shadow: inset 0 0 0 1px #d9c9ec; }
#session button:hover { background: #e6d5fa; }

.console {
  overflow: hidden;
  border-radius: 2rem;
  border: 1px solid #c1b1df;
  padding: clamp(0.7rem, 2.4vw, 1.35rem);
  background: linear-gradient(151deg, #eae1ff, #d2bfee);
  box-shadow: 0 26px 60px #644d9330, inset 0 2px #fff9, inset 0 -4px #a58ac02c;
}

.panel {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  border: clamp(5px, 1.2vw, 9px) solid #4b3a67;
  border-radius: 1.1rem;
  box-shadow: 0 2px 1px #fff8;
}
.sky { aspect-ratio: 2.06; background: linear-gradient(#e5d9ff, #f9dff0 70%, #fff0d7); }
.sun { position: absolute; aspect-ratio: 1; width: 14%; border-radius: 50%; top: 15%; right: 17%; background: #ffdc9a; box-shadow: 0 0 0 0.48rem #ffe7bc48; }
.cloud {
  position: absolute;
  top: 26%;
  left: 15%;
  width: 18%;
  height: 9%;
  border-radius: 2rem;
  background: #fff8fd;
  box-shadow: 2.5rem 0.6rem 0 -0.13rem #fff8fabb, 13rem 0.2rem 0 -0.15rem #fff8fabb;
}
.hill { position: absolute; width: 96%; height: 96%; left: -14%; bottom: -49%; border-radius: 59% 54% 0 0; background: #96c4b2; transform: rotate(7deg); }
.hill.far { left: 38%; bottom: -48%; background: #b3d4c5; transform: rotate(-16deg); }
.barn {
  position: absolute;
  right: 18%;
  bottom: 12%;
  width: 14%;
  height: 22%;
  border-radius: 0.15rem 0.15rem 0.25rem 0.25rem;
  background: #f3aebe;
  box-shadow: inset 0 -3px #dc8aa4;
}
.barn::before {
  content: "";
  position: absolute;
  inset: -60% -13% auto;
  height: 72%;
  background: #bd769b;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.barn::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 37%;
  width: 26%;
  height: 57%;
  border-radius: 0.3rem 0.3rem 0 0;
  background: #855a8a;
}
.hinge { margin: 0.55rem auto; width: 43%; height: 0.47rem; border-radius: 1rem; background: #b6a0d4; box-shadow: inset 0 2px #8a6eae55, 0 1px #fff8; }
.lower { aspect-ratio: 2.95; background: linear-gradient(149deg, #c8e9db, #9ec8b7); }
.furrows { position: absolute; inset: 15% -35% -35% 15%; transform: rotate(-15deg); background: repeating-linear-gradient(164deg, #94bca9 0 11%, #b5d8c4 11% 17%, #a8cdb7 17% 22%); border-top: 2px solid #d3ebdb; }
.sprout {
  position: absolute;
  left: 15%;
  bottom: 23%;
  width: 3px;
  height: 26%;
  border-radius: 2px;
  background: #518a73;
}
.sprout::before, .sprout::after { content: ""; position: absolute; top: 0; width: 1.1rem; height: 0.57rem; background: #6aa68a; border-radius: 0 90% 0 90%; }
.sprout::before { right: 1px; transform: rotate(14deg); }
.sprout::after { left: 1px; top: -3px; transform: scaleX(-1) rotate(14deg); }

#game { width: 100%; height: clamp(400px, 77svh, 680px); background: #282037; border-radius: 0.85rem; overflow: hidden; }
#touch-controls { display: none; }

@media (any-pointer: coarse), (max-width: 740px) {
  .playing #touch-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "stick actions" "utility utility";
    align-items: center;
    justify-items: center;
    gap: 0.35rem;
    margin-top: 0.7rem;
    user-select: none;
    -webkit-user-select: none;
  }
  .playing #game { height: clamp(290px, 61svh, 590px); }
  #stick {
    grid-area: stick;
    width: clamp(96px, 32vw, 132px);
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    position: relative;
    border: 2px solid #8f74b8;
    border-radius: 50%;
    background: radial-gradient(circle, #e5d6f7 0 37%, #d7c5ee 38% 58%, #beaad9);
    box-shadow: inset 0 4px 14px #6b52904a, 0 2px #fff7;
    touch-action: none;
  }
  .thumb {
    width: 45%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(circle at 36% 24%, #fff7ff, #cbb5ea 80%);
    box-shadow: 0 4px 13px #4e367766, inset 0 1px #fff;
    pointer-events: none;
    transform: translate(var(--x, 0px), var(--y, 0px));
  }
  .actions {
    grid-area: actions;
    display: grid;
    grid-template-columns: repeat(2, minmax(48px, 60px));
    gap: 0.32rem 0.44rem;
    transform: rotate(-10deg);
  }
  .control {
    aspect-ratio: 1;
    flex-direction: column;
    padding: 0;
    gap: 0;
    color: #45285b;
    background: #f3d9ed;
    border: 1px solid #e2add6;
    border-radius: 50%;
    box-shadow: 0 3px 0 #a07aab;
    transform: rotate(10deg);
    font-size: 0.75rem;
    line-height: 1.1;
  }
  .control:hover { filter: brightness(1.03); background: #f3d9ed; }
  .control b { font-size: 1.1rem; }
  .control.eat { background: #e7dcfa; border-color: #bfa9df; box-shadow: 0 3px 0 #947bbd; }
  .control.confirm { color: #224b3a; background: #c7eddb; border-color: #95cdb4; box-shadow: 0 3px 0 #79a992; }
  .control.tool { color: #624514; background: #ffe6b4; border-color: #ebc988; box-shadow: 0 3px 0 #bd9a64; }
  #touch-controls button { touch-action: none; }
  #touch-controls button.pressed { filter: brightness(0.92); box-shadow: none; }
  .utility { grid-area: utility; display: flex; justify-content: center; gap: 0.45rem; margin-top: 0.15rem; }
  .utility button { min-width: 44px; padding: 0.25rem 0.65rem; background: #5b427d; font-size: 0.82rem; }
}

@media (max-width: 740px) {
  main { grid-template-columns: minmax(0, 470px); gap: 1.35rem; align-content: start; --page-pad: 1.15rem; }
  h1 { font-size: clamp(2.3rem, 14.2cqw, 4.25rem); }
  .edition { margin-bottom: 0.76rem; }
  .intro { margin: 0.8rem 0 1.05rem; }
  .file-card { max-width: none; padding: 0.85rem; }
  .console { border-radius: 1.5rem; }
  body.playing .console { grid-row: 1; }
  #game { height: clamp(390px, 77svh, 600px); }
}

@media (orientation: landscape) and (any-pointer: coarse) and (max-height: 620px) {
  body.playing main {
    display: block;
    --page-pad: 0.36rem;
    min-height: 100dvh;
  }
  body.playing .setup { display: none; }
  body.playing .console { position: relative; padding: 0.35rem max(110px, 17vw); }
  body.playing #game {
    height: calc(100dvh - max(var(--page-pad), env(safe-area-inset-top))
      - max(var(--page-pad), env(safe-area-inset-bottom)) - 0.85rem);
  }
  body.playing #touch-controls { position: absolute; inset: 0 0.4rem; display: block; margin: 0; pointer-events: none; }
  #stick { position: absolute; bottom: 1.2rem; left: 0.35rem; pointer-events: auto; width: clamp(88px, 16vw, 128px); }
  .actions { position: absolute; bottom: 1.25rem; right: 0.2rem; pointer-events: auto; }
  .utility { position: absolute; top: 0.2rem; right: 0.15rem; gap: 0.15rem; pointer-events: auto; }
  .utility button { min-width: 28px; font-size: 0.71rem; padding: 0.2rem 0.35rem; }
}


