:root {
  color-scheme: light;
  --bg-top: #d6e2c2;
  --bg-bottom: #6f8c52;
  --panel: rgba(244, 241, 219, 0.9);
  --panel-strong: rgba(248, 245, 226, 0.97);
  --border: rgba(63, 80, 38, 0.28);
  --ink: #25311b;
  --muted: #5e6748;
  --accent: #47622e;
  --accent-strong: #2f441c;
  --accent-soft: #d8d39d;
  --shadow: 0 20px 54px rgba(42, 53, 24, 0.2);
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  font-size: 16px;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255,248,214,0.55), transparent 28%),
    radial-gradient(circle at bottom right, rgba(236,244,198,0.3), transparent 24%),
    linear-gradient(90deg, rgba(89,108,58,0.08) 0, rgba(89,108,58,0.08) 1px, transparent 1px, transparent 24px),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  background-size: auto, auto, 24px 24px, auto;
}

.standalone-app {
  min-height: 100vh;
  padding: 12px;
  position: relative;
}

.layout-shell {
  max-width: 1800px;
  margin: 0 auto;
  height: calc(100vh - 24px);
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 240px;
  gap: 14px;
  align-items: start;
}

.shell-panel {
  background:
    linear-gradient(180deg, rgba(250, 246, 223, 0.98), rgba(229, 223, 180, 0.92));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: calc(100vh - 24px);
  overflow: hidden;
  position: relative;
}

.shell-panel::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 5px;
  background: linear-gradient(90deg, #6f8546, #c9b45d, #8fa85b);
}

.shell-panel__eyebrow {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #6a5b2f;
  padding-top: 6px;
}

.shell-panel__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.shell-toggle-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.shell-toggle__label {
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #7a6a36;
}

.shell-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  cursor: pointer;
}

.shell-toggle__input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.shell-toggle__box {
  position: relative;
  display: block;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid rgba(84, 100, 46, 0.35);
  background: linear-gradient(180deg, rgba(255, 251, 231, 0.96), rgba(225, 215, 166, 0.98));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.7), 0 2px 6px rgba(54, 65, 33, 0.12);
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.shell-toggle__box::before {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(143, 168, 91, 0.18), rgba(71, 98, 46, 0.04));
}

.shell-toggle__box::after {
  content: '';
  position: absolute;
  left: 6px;
  top: 2px;
  width: 6px;
  height: 12px;
  border-right: 3px solid transparent;
  border-bottom: 3px solid transparent;
  transform: rotate(45deg);
  transition: border-color 120ms ease;
}

.shell-toggle:hover .shell-toggle__box,
.shell-toggle__input:focus-visible + .shell-toggle__box {
  transform: translateY(-1px);
  border-color: rgba(84, 100, 46, 0.58);
}

.shell-toggle__input:focus-visible + .shell-toggle__box {
  outline: 2px solid rgba(143, 168, 91, 0.42);
  outline-offset: 2px;
}

.shell-toggle__input:checked + .shell-toggle__box {
  background: linear-gradient(180deg, rgba(233, 245, 219, 1), rgba(164, 192, 105, 0.96));
  border-color: rgba(71, 98, 46, 0.7);
}

.shell-toggle__input:checked + .shell-toggle__box::after {
  border-color: #36531e;
}

.shell-list,
.shell-stats {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.shell-stats {
  grid-template-columns: 1fr 1fr;
  align-content: start;
}

.shell-list li,
.shell-stat {
  padding: 9px 10px;
  border-radius: 4px;
  background: rgba(255, 250, 231, 0.7);
  border: 1px solid rgba(109, 101, 52, 0.14);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.5);
}

.shell-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.shell-list span,
.shell-stat span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.shell-list strong,
.shell-stat strong {
  display: block;
  margin-top: 2px;
  font-size: 0.92rem;
  line-height: 1.2;
  color: var(--ink);
}

.shell-stat__value-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.shell-stat__value-row strong {
  margin-top: 0;
}

.shell-icon-btn {
  appearance: none;
  width: 26px;
  height: 26px;
  border: 1px solid rgba(86, 30, 22, 0.2);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 248, 244, 0.96), rgba(238, 216, 207, 0.94));
  color: #7e3628;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background-color 120ms ease;
}

.shell-icon-btn:hover,
.shell-icon-btn:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(86, 30, 22, 0.42);
  background: linear-gradient(180deg, rgba(255, 241, 235, 1), rgba(235, 204, 192, 0.98));
  outline: none;
}

.shell-icon-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.shell-panel--controls .shell-list li strong {
  margin-top: 0;
}

.shell-panel--controls {
  gap: 8px;
  overflow-y: auto;
}

.shell-panel--controls .shell-list {
  margin-top: 2px;
  gap: 6px;
}

.shell-panel--controls .shell-list li {
  padding: 7px 8px;
}

.shell-panel--controls .shell-list span,
.shell-panel--controls .shell-list strong {
  font-size: 0.78rem;
}

.touch-controls {
  display: none;
  position: absolute;
  inset: auto 18px 18px 18px;
  z-index: 12;
  grid-template-columns: auto auto;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  pointer-events: none;
}

.touch-controls[data-visible='true'] {
  display: grid;
}

.touch-controls__pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, 58px);
  gap: 6px;
  width: 186px;
  pointer-events: auto;
}

.touch-controls__actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  width: 72px;
  pointer-events: auto;
}

.touch-controls__core {
  grid-column: 2;
  grid-row: 2;
  border-radius: 10px;
  border: 1px solid rgba(84, 100, 46, 0.18);
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.38), rgba(132, 148, 88, 0.24));
}

.touch-controls__button {
  appearance: none;
  border: 1px solid rgba(66, 84, 36, 0.18);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 251, 231, 0.52), rgba(219, 210, 159, 0.34));
  color: var(--accent-strong);
  font: inherit;
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.38), 0 6px 14px rgba(54, 65, 33, 0.12);
  backdrop-filter: blur(6px);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: transform 80ms ease, border-color 80ms ease, background 80ms ease;
}

.touch-controls__button:hover,
.touch-controls__button:focus-visible {
  border-color: rgba(66, 84, 36, 0.5);
  outline: none;
}

.touch-controls__button:active,
.touch-controls__button[data-pressed='true'] {
  transform: translateY(1px) scale(0.98);
  background: linear-gradient(180deg, rgba(209, 222, 172, 0.7), rgba(166, 186, 106, 0.58));
  border-color: rgba(66, 84, 36, 0.42);
}

.touch-controls__button--up {
  grid-column: 2;
  grid-row: 1;
}

.touch-controls__button--left {
  grid-column: 1;
  grid-row: 2;
}

.touch-controls__button--right {
  grid-column: 3;
  grid-row: 2;
}

.touch-controls__button--down {
  grid-column: 2;
  grid-row: 3;
}

.touch-controls__button--confirm {
  min-height: 52px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(238, 245, 220, 0.56), rgba(171, 193, 107, 0.38));
}

.touch-controls__button--back {
  min-height: 52px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(245, 233, 220, 0.56), rgba(201, 164, 121, 0.38));
  color: #6b3d17;
}

.shell-goals {
  display: grid;
  gap: 6px;
  padding: 8px;
  border-radius: 4px;
  background: rgba(84, 100, 46, 0.12);
  border: 1px solid rgba(109, 101, 52, 0.16);
}

.shell-goals__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 7px;
}

.shell-goal {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  background: rgba(255, 250, 231, 0.7);
  border: 1px solid rgba(109, 101, 52, 0.14);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.5);
}

.shell-goal__copy {
  flex: 1 1 auto;
  min-width: 0;
}

.shell-goal__copy strong {
  display: block;
  font-size: 0.78rem;
  line-height: 1.2;
  color: var(--ink);
}

.shell-goal__copy span {
  display: block;
  margin-top: 1px;
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.shell-goal__tick {
  display: none;
  flex: 0 0 auto;
  width: 24px;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 900;
  line-height: 1;
  color: #3f6a2f;
  transform: scale(1);
  transition: color 140ms ease, transform 140ms ease;
}

.shell-goal[data-complete='true'] {
  border-color: rgba(71, 98, 46, 0.34);
  background: linear-gradient(180deg, rgba(233, 245, 219, 0.96), rgba(219, 237, 197, 0.9));
}

.shell-goal[data-complete='true'] .shell-goal__tick {
  display: block;
  transform: scale(1.08);
}

.shell-picker {
  margin-top: auto;
  display: grid;
  gap: 5px;
  padding: 8px;
  border-radius: 4px;
  background: rgba(84, 100, 46, 0.12);
  border: 1px solid rgba(109, 101, 52, 0.16);
}

.shell-picker__label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #6a5b2f;
}

.shell-picker__select {
  width: 100%;
  appearance: none;
  border: 1px solid rgba(80, 96, 45, 0.28);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(255,252,238,0.96), rgba(236,229,193,0.94));
  color: var(--ink);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  padding: 7px 9px;
  outline: none;
}

.shell-picker__select:focus {
  border-color: rgba(71, 98, 46, 0.6);
  box-shadow: 0 0 0 2px rgba(173, 160, 85, 0.18);
}

.shell-panel--stats .shell-stat:first-child,
.shell-panel--stats .shell-stat:nth-child(2),
.shell-panel--stats .shell-stat:nth-child(3),
.shell-panel--stats .shell-stat:nth-child(4) {
  grid-column: 1 / -1;
}

.stage-card {
  position: relative;
  background: linear-gradient(180deg, rgba(246, 244, 224, 0.92), rgba(232, 229, 199, 0.88));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  height: calc(100vh - 24px);
  padding: 10px;
}

.stage-view {
  min-height: 100%;
  height: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.stage-view .game-screen-shell {
  width: 100%;
  min-height: 100%;
  padding: 0;
  border-radius: 22px;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.stage-view .monster-stage {
  position: relative;
  width: min(100%, calc((100vh - 54px) * 1.48));
  max-width: 1760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stage-view .monster-stage canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
}

.stage-view .monster-statusbar {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 40px;
}

.stage-view #mtCanvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-width: 3px !important;
  box-shadow: 0 16px 36px rgba(55, 60, 29, 0.22);
}

.stage-view #mtMsg {
  max-width: min(100%, 100%);
  font-size: 1.08rem !important;
  line-height: 1.3;
  letter-spacing: 0.02em;
  color: var(--ink);
  font-weight: 700;
  background: var(--panel-strong);
  border: 1px solid rgba(255,240,182,0.18);
  border-radius: 6px;
  padding: 8px 14px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
  width: 100%;
}

.shell-btn {
  appearance: none;
  border: 1px solid rgba(44, 75, 48, 0.18);
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

.shell-btn:hover,
.shell-btn:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(44, 75, 48, 0.34);
  outline: none;
}

.shell-btn--accent {
  background: var(--accent);
  color: #f4f9ef;
}

.shell-btn--ghost {
  background: rgba(217, 235, 203, 0.74);
}

.shell-btn--danger {
  background: linear-gradient(180deg, #a64d3b, #7e3628);
  color: #fff6ef;
  border-color: rgba(86, 30, 22, 0.45);
}

.shell-panel__action {
  margin-top: auto;
  width: 100%;
  justify-content: center;
}

.fullscreen-mode {
  padding: 0;
}

.fullscreen-mode .layout-shell {
  max-width: none;
  min-height: 100vh;
  grid-template-columns: 200px minmax(0, 1fr) 220px;
  gap: 10px;
  padding: 10px;
}

.fullscreen-mode .shell-panel {
  height: calc(100vh - 20px);
  border-radius: 22px;
}

.fullscreen-mode .stage-card {
  height: calc(100vh - 20px);
  border-radius: 22px;
  padding: 8px;
}

.fullscreen-mode .stage-view,
.fullscreen-mode .stage-view .game-screen-shell {
  min-height: 100%;
}

@media (max-width: 1120px) {
  .layout-shell {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .shell-panel {
    min-height: 0;
    height: auto;
  }

  .shell-stats {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .shell-stat--score {
    grid-column: auto;
  }

  .shell-panel--stats .shell-stat:first-child,
  .shell-panel--stats .shell-stat:nth-child(2),
  .shell-panel--stats .shell-stat:nth-child(3),
  .shell-panel--stats .shell-stat:nth-child(4) {
    grid-column: auto;
  }

  .stage-view {
    min-height: 0;
  }
}

@media (max-width: 720px) {
  .standalone-app {
    padding: 10px;
  }

  .stage-card {
    border-radius: 20px;
  }

  .shell-panel {
    border-radius: 20px;
    padding: 12px;
  }

  .shell-stats {
    grid-template-columns: 1fr 1fr;
  }

  .stage-view .monster-stage {
    width: min(100%, calc((100vh - 44px) * 1.5));
  }

  .touch-controls__pad {
    grid-template-rows: repeat(3, 50px);
    width: 162px;
  }

  .touch-controls__button--confirm,
  .touch-controls__button--back {
    min-height: 46px;
  }

  .touch-controls {
    inset: auto 12px 12px 12px;
    gap: 12px;
  }

  .touch-controls__actions {
    width: 62px;
  }

}