:root {
  color-scheme: dark;
  font-family: system-ui, "Thonburi", "Noto Sans Thai", sans-serif;
  background: #30291f;
  color: #fff8ec;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
button { font: inherit; }

.game {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background: #453827 url("assets/home-close.webp") center / cover;
}

@media (orientation: portrait) {
  .game { background-image: url("assets/portrait-close.webp"); }
}

#scene, .scene-targets { position: absolute; inset: 0; width: 100%; height: 100%; }
#scene { touch-action: none; }
.scene-targets { pointer-events: none; }
.scene-target {
  position: absolute;
  border: 0;
  border-radius: 12px;
  padding: 0;
  background: transparent;
  pointer-events: auto;
  cursor: pointer;
}

.scene-target:focus-visible, .control:focus-visible {
  outline: 3px solid #fff9e5;
  outline-offset: 4px;
}

.identity {
  position: absolute;
  top: max(24px, env(safe-area-inset-top));
  left: max(26px, env(safe-area-inset-left));
  padding: 12px 20px 14px;
  background: #261d13a8;
  border: 1px solid #ffefd62e;
  border-radius: 20px;
  pointer-events: none;
  backdrop-filter: blur(12px);
}

.identity h1 {
  margin: 0;
  font: 500 clamp(1.9rem, 4vw, 2.75rem)/1 Georgia, "Times New Roman", serif;
  letter-spacing: -.065em;
}

.identity p { margin: 5px 0 0; font-size: .875rem; color: #fff0da; }

.top-actions { position: absolute; z-index: 2; top: max(24px, calc(env(safe-area-inset-top) + 8px)); right: max(24px, calc(env(safe-area-inset-right) + 8px)); display: flex; align-items: flex-start; gap: 5px; }
.weather { position: relative; text-align: right; }
.weather summary, .install-button { display: inline-flex; align-items: center; min-height: 44px; padding: 8px 11px; border: 1px solid #ffefd644; border-radius: 22px; background: #2c2219e0; color: #fff6e6; font-size: .875rem; cursor: pointer; white-space: nowrap; }
.install-button[hidden] { display: none; }
.weather summary::-webkit-details-marker { display: none; }
.weather summary:focus-visible, .install-button:focus-visible { outline: 3px solid #fff9e5; outline-offset: 3px; }
.weather-panel { position: absolute; right: 0; width: min(300px, calc(100vw - 26px)); margin-top: 6px; padding: 11px 14px; border: 1px solid #ffefd644; border-radius: 18px; color: #fff6e6; background: #2c2219f2; text-align: left; font-size: .9rem; line-height: 1.5; }
.weather-panel p { margin: 0 0 7px; }
.weather-panel .control { border-color: #ffefd660; margin: 3px 2px 5px 0; }
.weather-panel a { display: block; margin-top: 3px; color: #f2d5ac; font-size: .82rem; }
.install-dialog { width: min(24rem, calc(100% - 32px)); max-height: 90dvh; padding: 20px; border: 1px solid #ffefd644; border-radius: 20px; background: #2c2219; color: #fff6e6; line-height: 1.6; }
.install-dialog::backdrop { background: #20170d9e; }
.install-dialog h2 { margin: 0; font-size: 1.12rem; }
.install-dialog ol { padding-inline-start: 23px; }
.install-dialog li + li { margin-top: 6px; }
.install-dialog form { text-align: end; }

.controls {
  position: absolute;
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 12px));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 16px);
  text-align: center;
  pointer-events: none;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
  padding: 5px;
  border: 1px solid #ffefd633;
  border-radius: 24px;
  background: #2d2219e0;
  backdrop-filter: blur(16px);
  box-shadow: 0 5px 24px #22180d53;
  pointer-events: auto;
}

.control {
  border: 1px solid transparent;
  padding: 9px 15px;
  min-height: 44px;
  border-radius: 18px;
  background: transparent;
  color: #fff6e6;
  font-size: .94rem;
  white-space: nowrap;
  cursor: pointer;
}

.control:hover { background: #fff7dc24; }
.control.cookie { background: #efc491; color: #33231b; font-weight: 700; }
.control.cookie:hover { background: #ffdbad; }
.control[aria-pressed="true"] { background: #566547; border-color: #bdcba2; }
.control:active { transform: scale(.97); }

.notice {
  display: table;
  margin: 0 auto 8px;
  border-radius: 14px;
  padding: 8px 14px;
  background: #2d2219ed;
  font-size: .94rem;
  line-height: 1.45;
  color: #fff8ec;
}
.notice[hidden] { display: none; }
.treat { pointer-events: auto; cursor: pointer; border: 1px solid #ffefd674; }
.treat:focus-visible { outline: 3px solid #fff9e5; outline-offset: 3px; }
.no-script { position: absolute; bottom: 95px; left: 50%; transform: translateX(-50%); }

@media (max-width: 540px) {
  .identity { left: max(13px, env(safe-area-inset-left)); top: max(13px, env(safe-area-inset-top)); padding: 8px 14px 10px; border-radius: 16px; }
  .control { padding-inline: clamp(7px, 3vw, 12px); }
  .notice { max-width: 95%; }
  .top-actions { top: max(13px, calc(env(safe-area-inset-top) + 5px)); right: max(13px, calc(env(safe-area-inset-right) + 5px)); }
}

@media (max-width: 360px) {
  .top-actions { flex-direction: row-reverse; flex-wrap: wrap; width: 146px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .identity { top: max(10px, calc(env(safe-area-inset-top) + 5px)); left: max(14px, calc(env(safe-area-inset-left) + 6px)); padding: 7px 13px; border-radius: 14px; }
  .identity h1 { font-size: 1.85rem; }
  .identity p { margin-top: 3px; }
  .controls { left: auto; right: max(12px, calc(env(safe-area-inset-right) + 6px)); bottom: max(10px, calc(env(safe-area-inset-bottom) + 5px)); transform: none; max-width: calc(100% - 24px); }
  .top-actions { top: max(10px, calc(env(safe-area-inset-top) + 5px)); right: max(12px, calc(env(safe-area-inset-right) + 6px)); }
}

@media (prefers-reduced-motion: reduce) {
  .control:active { transform: none; }
}
