:root {
  color-scheme: light;
  --ink: #1f2933;
  --muted: #64748b;
  --line: #1e2b37;
  --paper: #edf2d5;
  --panel: #fffced;
  --grass: #86c06a;
  --path: #d6ba73;
  --water: #5aa7c7;
  --accent: #d94841;
  --blue: #2563eb;
  --green: #138a5b;
  --gold: #c47f17;
  --shadow: 0 8px 0 rgba(30, 43, 55, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(126, 177, 88, 0.34), rgba(232, 206, 119, 0.22)),
    var(--paper);
  color: var(--ink);
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    monospace;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) 380px;
  gap: 18px;
  width: min(1180px, calc(100vw - 28px));
  margin: 14px auto;
}

.game-area,
.panel {
  border: 4px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.game-area {
  padding: 14px;
}

.top-bar,
.battle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(24px, 4vw, 42px);
}

h2 {
  font-size: 18px;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-strip span,
#placeBadge {
  border: 2px solid var(--line);
  background: #fff0a6;
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 800;
  box-shadow: inset -2px -2px 0 rgba(30, 43, 55, 0.16);
}

.cloud-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 118px 118px auto;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.cloud-row input,
.cloud-row button,
.cloud-row span {
  min-height: 38px;
  border: 2px solid var(--line);
}

.cloud-row input {
  background: #fffef4;
}

.cloud-row button {
  background: #d7f0ff;
  font-weight: 800;
}

.cloud-row span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #dcfce7;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 800;
}

.viewport-frame {
  position: relative;
  margin-top: 12px;
  border: 6px solid var(--line);
  background: #18242f;
  aspect-ratio: 4 / 3;
  box-shadow:
    inset 0 0 0 4px #52616f,
    inset 0 0 0 8px #f4f1d7;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.toast {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  min-height: 48px;
  border: 3px solid var(--line);
  background: rgba(255, 252, 237, 0.96);
  padding: 10px;
  font-size: 14px;
  line-height: 1.35;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 140ms ease, transform 140ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.controls {
  display: grid;
  grid-template-columns: 52px 52px 1fr 52px 52px;
  gap: 8px;
  margin-top: 12px;
}

.icon-button,
.command-button,
.form-row button,
.form-grid button,
.battle-actions button,
.tab {
  border: 2px solid var(--line);
  background: #fffced;
  color: var(--ink);
  min-height: 42px;
  font-weight: 800;
  box-shadow: inset -3px -3px 0 rgba(31, 41, 51, 0.16);
}

.icon-button {
  aspect-ratio: 1;
  font-size: 18px;
}

.command-button {
  background: #d7f0ff;
  min-width: 0;
  white-space: nowrap;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 28px);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 3px solid var(--line);
}

.tab {
  border-width: 0 2px 0 0;
  min-width: 0;
}

.tab:last-child {
  border-right: 0;
}

.tab.active {
  background: #bfe68b;
}

.tab-panel {
  display: none;
  padding: 12px;
  min-height: 280px;
  border-bottom: 3px solid var(--line);
}

.tab-panel.active {
  display: block;
}

.form-row,
.form-grid {
  display: grid;
  gap: 8px;
}

.form-row {
  grid-template-columns: minmax(0, 1fr) 118px 68px;
}

#itemForm {
  grid-template-columns: minmax(0, 1fr) 68px;
}

.form-grid {
  grid-template-columns: minmax(0, 1fr) 110px;
}

.form-grid button {
  grid-column: 1 / -1;
}

input,
select {
  min-width: 0;
  border: 2px solid var(--line);
  background: #fffef4;
  color: var(--ink);
  padding: 9px 8px;
}

.list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 2px solid var(--line);
  background: #fffef4;
  padding: 8px;
}

.entry strong {
  display: block;
  overflow-wrap: anywhere;
}

.entry small {
  color: var(--muted);
}

.entry button {
  border: 2px solid var(--line);
  background: #ffd2c7;
  min-height: 32px;
  font-weight: 800;
}

.battle-box {
  padding: 12px;
}

.battle-box p {
  min-height: 58px;
  margin: 10px 0;
  line-height: 1.45;
}

.battle-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.battle-actions button:nth-child(1) {
  background: #fee2e2;
}

.battle-actions button:nth-child(2) {
  background: #dcfce7;
}

.battle-actions button:nth-child(3) {
  background: #e0f2fe;
}

.battle-actions button:nth-child(4) {
  background: #fef3c7;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .panel {
    min-height: auto;
  }
}

@media (max-width: 560px) {
  .shell {
    width: calc(100vw - 16px);
    margin: 8px auto;
  }

  .game-area {
    padding: 10px;
  }

  .top-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .controls {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .controls .icon-button,
  .controls .command-button {
    font-size: 14px;
    min-height: 54px;
  }

  .cloud-row {
    grid-template-columns: 1fr 1fr;
  }

  .cloud-row input,
  .cloud-row span {
    grid-column: 1 / -1;
  }

  .form-row,
  #itemForm {
    grid-template-columns: 1fr;
  }
}
