:root {
  color-scheme: dark;
  --bg: #171e1c;
  --bg-deep: #101614;
  --panel: rgba(23, 31, 28, 0.86);
  --panel-soft: rgba(19, 28, 25, 0.68);
  --border: rgba(234, 219, 186, 0.2);
  --text: #f7f1e3;
  --muted: #bcb8a9;
  --sand: #e1b66d;
  --sand-light: #f3d998;
  --teal: #93d6c6;
  --teal-deep: #347e78;
  --danger: #e98977;
  --danger-light: #ffc1a8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--bg);
}

body {
  color: var(--text);
  overscroll-behavior-x: none;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

[inert] {
  pointer-events: none !important;
}

.page-shell {
  width: 100%;
  overflow-x: hidden;
  background: #f2f6f3;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 520px;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 44%, rgba(75, 114, 95, 0.12), transparent 38%),
    linear-gradient(145deg, var(--bg-deep), var(--bg));
}

#scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  outline: none;
}

#scene.is-dragging {
  cursor: grabbing;
}

#scene:focus-visible {
  outline: 2px solid var(--sand-light);
  outline-offset: -4px;
}

.grain-noise {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.12;
  mix-blend-mode: soft-light;
  background-image:
    radial-gradient(circle at 20% 15%, rgba(255, 255, 255, 0.19) 0 0.6px, transparent 0.9px),
    radial-gradient(circle at 75% 70%, rgba(255, 255, 255, 0.12) 0 0.5px, transparent 0.8px);
  background-size: 5px 5px, 7px 7px;
}

.site-head {
  position: absolute;
  z-index: 3;
  top: max(22px, env(safe-area-inset-top));
  left: max(24px, env(safe-area-inset-left));
  width: min(430px, calc(100vw - 48px));
  pointer-events: none;
  text-shadow: 0 3px 22px rgba(0, 0, 0, 0.38);
}

.eyebrow,
.panel-kicker {
  margin: 0 0 8px;
  color: var(--sand-light);
  font-size: 0.67rem;
  font-weight: 760;
  letter-spacing: 0.16em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 7px;
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  line-height: 1.08;
  letter-spacing: 0.035em;
}

.lead {
  max-width: 380px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: clamp(0.78rem, 1.3vw, 0.94rem);
  line-height: 1.65;
}

.game-hud {
  position: absolute;
  z-index: 3;
  top: max(24px, env(safe-area-inset-top));
  right: max(24px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: repeat(3, minmax(86px, auto));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(16, 23, 21, 0.7);
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(16px);
}

.metric {
  display: grid;
  gap: 3px;
  min-width: 92px;
  padding: 10px 13px;
  border-left: 1px solid var(--border);
}

.metric:first-child {
  border-left: 0;
}

.metric > span,
.metric small {
  color: var(--muted);
  font-size: 0.61rem;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.metric strong {
  font-size: 0.94rem;
  font-variant-numeric: tabular-nums;
}

.metric-time strong {
  color: var(--sand-light);
  font-size: 1.12rem;
}

.metric-damage strong {
  color: var(--danger-light);
}

.progress-panel {
  position: absolute;
  z-index: 3;
  top: 138px;
  left: max(24px, env(safe-area-inset-left));
  width: min(270px, calc(100vw - 48px));
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-soft);
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(16px);
}

.progress-row + .progress-row {
  margin-top: 12px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.68rem;
}

.progress-label strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.progress-track {
  position: relative;
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
}

.progress-value {
  position: relative;
  z-index: 1;
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  transition: width 120ms linear;
}

.progress-exposure {
  background: linear-gradient(90deg, var(--teal-deep), var(--teal));
  box-shadow: 0 0 18px rgba(147, 214, 198, 0.48);
}

.progress-damage {
  background: linear-gradient(90deg, #c16a5b, var(--danger));
  box-shadow: 0 0 18px rgba(233, 137, 119, 0.42);
}

.target-marker {
  position: absolute;
  top: 0;
  z-index: 2;
  width: 2px;
  height: 100%;
  background: rgba(255, 248, 224, 0.95);
  box-shadow: 0 0 4px rgba(255, 248, 224, 0.85);
}

.target-marker-exposure {
  left: 80%;
}

.target-marker-damage {
  left: 25%;
}

.tool-status {
  position: absolute;
  z-index: 3;
  top: 258px;
  left: max(24px, env(safe-area-inset-left));
  padding: 7px 11px;
  border: 1px solid rgba(234, 219, 186, 0.14);
  border-radius: 999px;
  color: var(--sand-light);
  background: rgba(16, 23, 21, 0.48);
  font-size: 0.7rem;
  pointer-events: none;
}

.control-panel {
  position: absolute;
  z-index: 4;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  width: min(380px, calc(100vw - 48px));
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(20px) saturate(1.1);
}

.tool-row,
.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-row {
  margin-top: 9px;
}

.tool-button,
.button {
  min-height: 46px;
  padding: 8px 10px;
  border: 1px solid rgba(239, 227, 201, 0.17);
  border-radius: 11px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease, opacity 140ms ease;
}

.tool-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 58px;
  text-align: left;
}

.tool-button:hover:not(:disabled),
.button:hover:not(:disabled) {
  border-color: rgba(243, 217, 152, 0.62);
  background: rgba(243, 217, 152, 0.1);
}

.tool-button:active:not(:disabled),
.button:active:not(:disabled) {
  transform: translateY(1px);
}

.tool-button:focus-visible,
.button:focus-visible {
  outline: 2px solid var(--sand-light);
  outline-offset: 2px;
}

.tool-button.is-selected {
  border-color: rgba(147, 214, 198, 0.86);
  background: rgba(52, 126, 120, 0.35);
  box-shadow: inset 0 0 0 1px rgba(147, 214, 198, 0.24), 0 8px 24px rgba(20, 65, 61, 0.2);
}

.tool-icon {
  position: relative;
  flex: 0 0 auto;
  display: block;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
}

.tool-icon::after {
  position: absolute;
  content: "";
}

.tool-icon-brush::after {
  top: 8px;
  left: 8px;
  width: 16px;
  height: 9px;
  border: 2px solid var(--sand-light);
  border-radius: 2px 5px 5px 2px;
  transform: rotate(-30deg);
}

.tool-icon-brush::before {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 20px;
  height: 2px;
  content: "";
  background: var(--sand-light);
  transform: rotate(-30deg);
  transform-origin: right center;
}

.tool-icon-spatula::after {
  top: 5px;
  left: 13px;
  width: 7px;
  height: 20px;
  border: 2px solid var(--danger-light);
  border-radius: 2px 2px 5px 5px;
  transform: rotate(28deg);
}

.tool-copy {
  display: grid;
  gap: 2px;
}

.tool-copy strong {
  font-size: 0.78rem;
}

.tool-copy small {
  color: var(--muted);
  font-size: 0.62rem;
}

.button {
  font-size: 0.78rem;
  font-weight: 720;
}

.button-primary {
  color: #1b211b;
  border-color: rgba(243, 217, 152, 0.68);
  background: linear-gradient(135deg, #f2d693, #d8a85d);
  box-shadow: 0 10px 28px rgba(216, 168, 93, 0.16);
}

.button-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #ffdfa0, #e7b972);
}

.button-quiet {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
}

.key-help {
  margin: 10px 1px 0;
  color: rgba(188, 184, 169, 0.74);
  font-size: 0.62rem;
  line-height: 1.5;
}

.status-line {
  position: absolute;
  z-index: 3;
  bottom: max(28px, env(safe-area-inset-bottom));
  left: 50%;
  max-width: min(420px, calc(100vw - 32px));
  margin: 0;
  padding: 8px 13px;
  border: 1px solid rgba(234, 219, 186, 0.13);
  border-radius: 999px;
  color: rgba(247, 241, 227, 0.87);
  background: rgba(16, 23, 21, 0.52);
  font-size: 0.7rem;
  line-height: 1.4;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.overlay-panel {
  position: absolute;
  z-index: 8;
  top: 50%;
  left: 50%;
  width: min(410px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid rgba(234, 219, 186, 0.27);
  border-radius: 18px;
  background: rgba(18, 27, 24, 0.94);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.52);
  transform: translate(-50%, -50%);
  backdrop-filter: blur(24px);
}

.overlay-panel[hidden] {
  display: none;
}

.overlay-panel h2 {
  margin: 0 0 14px;
  font-size: 1.4rem;
}

.overlay-panel > p:not(.panel-kicker) {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.65;
}

.result-reason {
  min-height: 1.45em;
  margin-bottom: 13px;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 18px;
}

.result-grid div {
  display: grid;
  gap: 5px;
  min-height: 68px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.045);
}

.result-grid span {
  color: var(--muted);
  font-size: 0.65rem;
}

.result-grid strong {
  font-size: 1.02rem;
  font-variant-numeric: tabular-nums;
}

.result-panel[data-result="failure"] h2,
.result-panel[data-result="failure"] .result-reason {
  color: var(--danger-light);
}

.overlay-panel .button {
  width: 100%;
}

.error-box {
  position: absolute;
  z-index: 10;
  top: 50%;
  left: 50%;
  width: min(480px, calc(100vw - 40px));
  margin: 0;
  padding: 16px 18px;
  border: 1px solid rgba(255, 193, 168, 0.44);
  border-radius: 14px;
  color: var(--danger-light);
  background: rgba(55, 20, 17, 0.94);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
}

.usage-section,
.comments-stub,
.app-comments,
.app-comment-form-section {
  width: min(1040px, calc(100% - 32px));
  margin-inline: auto;
}

.usage-section {
  padding: 54px 0 30px;
  color: #17201e;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
}

.usage-kicker {
  margin: 0 0 7px;
  color: #347e78;
  font-size: 0.68rem;
  font-weight: 760;
  letter-spacing: 0.16em;
}

.usage-section h2 {
  margin: 0 0 26px;
  color: #17201e;
  font-size: clamp(1.35rem, 2.4vw, 1.8rem);
}

.usage-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 28px;
}

.usage-grid article {
  min-width: 0;
  padding-top: 14px;
  border-top: 1px solid #9db1aa;
}

.usage-grid h3 {
  margin: 0 0 7px;
  color: #17201e;
  font-size: 1.05rem;
}

.usage-grid p,
.comments-stub p,
.app-comments p,
.app-comment-form-section p {
  margin: 0;
  color: #465a54;
  line-height: 1.8;
  overflow-wrap: anywhere;
}

.comments-stub,
.app-comments,
.app-comment-form-section {
  margin-bottom: 42px;
  color: #17201e;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
  overflow-wrap: anywhere;
}

.comments-stub {
  padding: 24px;
  border: 1px solid #d6e0db;
  border-radius: 14px;
  background: #ffffff;
}

.comments-stub h2,
.app-comments h2,
.app-comment-form-section h2 {
  margin: 0 0 10px;
  color: #17201e;
  font-size: 1.18rem;
}

.app-comments,
.app-comment-form-section {
  max-width: 1040px;
}

@media (max-width: 900px) {
  .site-head {
    max-width: min(48vw, 360px);
  }

  .game-hud {
    top: 100px;
    right: 16px;
    left: 16px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric {
    min-width: 0;
    padding: 8px 9px;
  }

  .progress-panel {
    top: 173px;
    right: 16px;
    left: 16px;
    width: auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 10px 12px;
  }

  .progress-row + .progress-row {
    margin-top: 0;
  }

  .tool-status {
    top: 230px;
    left: 16px;
  }

  .control-panel {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
    width: auto;
    padding: 12px;
  }

  .status-line {
    bottom: 185px;
  }

  .key-help {
    display: none;
  }
}

@media (max-width: 580px) {
  .app-shell {
    min-height: 500px;
  }

  .site-head {
    top: max(13px, env(safe-area-inset-top));
    left: max(16px, env(safe-area-inset-left));
    width: calc(100vw - 32px);
  }

  .eyebrow {
    margin-bottom: 5px;
    font-size: 0.56rem;
  }

  h1 {
    margin-bottom: 5px;
    font-size: 1.34rem;
  }

  .lead {
    max-width: 300px;
    font-size: 0.7rem;
  }

  .game-hud {
    top: 89px;
    right: 10px;
    left: 10px;
  }

  .metric {
    padding: 7px 5px;
  }

  .metric > span,
  .metric small {
    font-size: 0.52rem;
  }

  .metric strong {
    font-size: 0.78rem;
  }

  .metric-time strong {
    font-size: 0.9rem;
  }

  .progress-panel {
    top: 149px;
    right: 10px;
    left: 10px;
    gap: 8px;
    padding: 8px 9px;
  }

  .progress-label {
    margin-bottom: 4px;
    font-size: 0.6rem;
  }

  .progress-track {
    height: 6px;
  }

  .tool-status {
    top: 201px;
    left: 12px;
    padding: 5px 9px;
    font-size: 0.62rem;
  }

  .control-panel {
    right: 9px;
    bottom: max(9px, env(safe-area-inset-bottom));
    left: 9px;
    padding: 9px;
  }

  .tool-button {
    min-height: 53px;
    gap: 6px;
    padding: 7px 6px;
  }

  .tool-icon {
    width: 28px;
    height: 28px;
  }

  .tool-copy strong {
    font-size: 0.72rem;
  }

  .tool-copy small {
    font-size: 0.57rem;
  }

  .button {
    min-height: 45px;
    padding: 7px 6px;
    font-size: 0.7rem;
  }

  .status-line {
    bottom: 177px;
    max-width: calc(100vw - 26px);
    padding: 7px 10px;
    font-size: 0.63rem;
    white-space: nowrap;
  }

  .overlay-panel {
    padding: 18px;
  }

  .overlay-panel h2 {
    font-size: 1.2rem;
  }

  .usage-section {
    width: calc(100% - 28px);
    padding-top: 38px;
  }

  .usage-grid {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .comments-stub,
  .app-comments,
  .app-comment-form-section {
    width: calc(100% - 28px);
  }

  .comments-stub {
    padding: 18px;
  }
}

@media (max-width: 340px) {
  .tool-icon {
    display: none;
  }

  .tool-copy {
    justify-items: center;
  }

  .status-line {
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tool-button,
  .button,
  .progress-value {
    transition: none;
  }
}

/* Keep the compact landscape layout inside a short 844x390-style viewport. */
@media (max-height: 480px) and (min-width: 700px) {
  html,
  body {
    min-height: 0;
  }

  .app-shell {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .site-head {
    top: 10px;
    left: 16px;
    width: min(330px, 40vw);
  }

  .eyebrow {
    margin-bottom: 4px;
    font-size: 0.56rem;
  }

  h1 {
    margin-bottom: 4px;
    font-size: 1.22rem;
  }

  .lead {
    max-width: 320px;
    font-size: 0.64rem;
    line-height: 1.4;
  }

  .game-hud {
    top: 10px;
    right: 16px;
    left: auto;
    width: min(312px, 38vw);
  }

  .metric {
    min-width: 0;
    padding: 7px 8px;
  }

  .metric > span,
  .metric small {
    font-size: 0.52rem;
  }

  .metric strong {
    font-size: 0.78rem;
  }

  .metric-time strong {
    font-size: 0.9rem;
  }

  .progress-panel {
    top: 86px;
    right: auto;
    left: 16px;
    width: 220px;
    display: block;
    padding: 8px 10px;
  }

  .progress-row + .progress-row {
    margin-top: 8px;
  }

  .progress-label {
    margin-bottom: 4px;
    font-size: 0.6rem;
  }

  .progress-track {
    height: 6px;
  }

  .tool-status {
    top: 177px;
    left: 16px;
    padding: 5px 9px;
    font-size: 0.6rem;
  }

  .control-panel {
    top: auto;
    right: 16px;
    bottom: 10px;
    left: auto;
    width: min(320px, 40vw);
    padding: 8px;
  }

  .tool-button {
    min-height: 48px;
    padding: 6px 7px;
  }

  .tool-icon {
    width: 26px;
    height: 26px;
  }

  .tool-copy strong {
    font-size: 0.68rem;
  }

  .tool-copy small {
    font-size: 0.54rem;
  }

  .action-row {
    margin-top: 6px;
  }

  .button {
    min-height: 40px;
    padding: 6px 8px;
    font-size: 0.68rem;
  }

  .status-line {
    right: auto;
    bottom: 11px;
    left: 16px;
    max-width: 235px;
    padding: 6px 9px;
    font-size: 0.6rem;
    text-align: left;
    transform: none;
  }
}
