:root {
  color-scheme: light;
  --bg: #dcdcdc;
  --body-a: #e8e5e1;
  --body-b: #cbc5bc;
  --shell-stroke: rgba(0, 0, 0, 0.16);
  --ink: rgba(16, 16, 26, 0.9);
  --muted: rgba(16, 16, 26, 0.62);
  --screen-bg: #9eb15a;
}

html,
body {
  height: 100%;
  min-height: 100svh;
  min-height: 100dvh;
  margin: 0;
}

body {
  overflow: hidden;
  background: radial-gradient(1300px 900px at 50% 10%, #efefef 0%, var(--bg) 48%, #c9c9c9 100%);
  font-family: "Avenir Next", "Trebuchet MS", "Helvetica Neue", Arial, sans-serif;
}

.gb-wrap {
  width: 100vw;
  height: var(--app-vh, 100svh);
  height: var(--app-vh, 100dvh);
  display: grid;
  place-items: center;
  padding: 12px;
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  padding-left: calc(12px + env(safe-area-inset-left));
  padding-right: calc(12px + env(safe-area-inset-right));
  box-sizing: border-box;
}

.gb-device {
  width: min(100%, 680px);
  height: min(100%, 980px);
  border-radius: 26px;
  border: 1px solid var(--shell-stroke);
  background: linear-gradient(165deg, var(--body-a) 0%, #efece8 18%, var(--body-a) 48%, var(--body-b) 100%);
  box-shadow:
    0 32px 64px -42px rgba(0, 0, 0, 0.7),
    inset -8px -18px 26px rgba(0, 0, 0, 0.06),
    inset 8px 10px 14px rgba(255, 255, 255, 0.45);
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px;
  box-sizing: border-box;
}

.gb-side-display {
  grid-row: 2;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  background: linear-gradient(180deg, rgba(226, 227, 234, 0.85), rgba(212, 214, 222, 0.92));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.52);
  padding: 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(180px, 260px);
  align-items: stretch;
  gap: 8px;
  min-width: 0;
}

.gb-main-display {
  grid-row: 1;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.28);
  background: var(--screen-bg);
  box-shadow:
    inset 0 0 0 2px rgba(60, 72, 38, 0.24),
    inset 0 -10px 18px rgba(42, 56, 24, 0.14);
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.gb-agent {
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(0, 0, 0, 0.08);
  padding: 7px;
  min-width: 0;
}

.gb-status-line {
  font-size: 11px;
  line-height: 1.32;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gb-status-line.main {
  font-size: 12px;
  font-weight: 700;
}

.gb-status-line.thought {
  color: var(--muted);
  font-size: 10px;
}

.gb-status-line.foot {
  margin-top: 2px;
  text-align: center;
  color: rgba(24, 26, 42, 0.72);
  font-weight: 600;
  font-size: 10px;
}

.gb-hp-track {
  margin: 5px 0;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.gb-hp-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

.gb-hp-fill.a {
  background: linear-gradient(90deg, #7f91ea, #5674dd);
}

.gb-hp-fill.b {
  background: linear-gradient(90deg, #ef987c, #e66f49);
}

.gb-action-stack {
  margin-top: 2px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gb-status-line.foot {
  grid-column: 1 / -1;
}

.gb-btn {
  width: 100%;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 12px;
  color: #fafaff;
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow:
    inset 0 3px 6px rgba(255, 255, 255, 0.16),
    0 10px 18px -14px rgba(0, 0, 0, 0.65);
  padding: 10px 9px;
  background: linear-gradient(180deg, #8d8e96, #60636b);
}

.gb-btn:disabled {
  opacity: 0.45;
  filter: grayscale(0.35);
  cursor: not-allowed;
}

.gb-btn.kind-defensive {
  background: linear-gradient(180deg, #3dbb5f, #1d8f3f);
}

.gb-btn.kind-offensive {
  background: linear-gradient(180deg, #d8434f, #a3252f);
}

.gb-btn.kind-neutral {
  background: linear-gradient(180deg, #8d8e96, #60636b);
}

.gb-btn-chip {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  font-weight: 700;
  font-size: 13px;
}

.gb-btn-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.gb-btn-name {
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gb-btn-sub {
  font-size: 11px;
  opacity: 0.92;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.flow-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 14px;
  padding-top: calc(14px + env(safe-area-inset-top));
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  padding-left: calc(14px + env(safe-area-inset-left));
  padding-right: calc(14px + env(safe-area-inset-right));
  box-sizing: border-box;
  pointer-events: auto;
  z-index: 30;
}

.flow-overlay.hidden {
  display: none;
}

.flow-card {
  width: min(420px, 100%);
  border-radius: 16px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  background: rgba(247, 247, 250, 0.96);
  box-shadow: 0 16px 38px -28px rgba(0, 0, 0, 0.55);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
  position: relative;
  z-index: 1;
}

.flow-card[hidden] {
  display: none;
}

.flow-card h2 {
  margin: 0 0 2px;
  font-size: 18px;
  color: rgba(22, 24, 38, 0.95);
}

.flow-label {
  font-size: 12px;
  color: rgba(20, 24, 36, 0.78);
}

.flow-input,
.flow-select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  background: rgba(255, 255, 255, 0.95);
  color: rgba(16, 16, 22, 0.92);
  font: inherit;
  padding: 10px 11px;
  box-sizing: border-box;
  touch-action: manipulation;
}

.flow-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.flow-btn {
  border: 1px solid rgba(0, 0, 0, 0.22);
  border-radius: 12px;
  background: linear-gradient(180deg, #4a70e8, #3554b8);
  color: #fff;
  font: inherit;
  font-weight: 700;
  padding: 10px 12px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.flow-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.2);
}

.flow-btn.small {
  padding-inline: 14px;
}

.flow-btn.subtle {
  background: linear-gradient(180deg, #a8acb8, #8a8f9e);
}

.flow-note {
  font-size: 13px;
  color: rgba(24, 26, 40, 0.76);
}

.flow-code {
  font: 700 18px ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: rgba(20, 24, 44, 0.92);
  letter-spacing: 0.08em;
}

.flow-error {
  margin-top: 10px;
  min-height: 20px;
  font-size: 12px;
  text-align: center;
  color: rgba(175, 42, 42, 0.95);
  pointer-events: none;
}

@media (max-width: 760px) {
  .gb-wrap {
    padding: 0;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    place-items: stretch;
  }

  .gb-device {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 6px;
    padding: 6px;
    border-radius: 0;
  }

  .gb-side-display {
    grid-template-columns: 1fr;
    padding: 6px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom) + 56px);
    gap: 6px;
  }

  .gb-btn {
    grid-template-columns: 24px 1fr;
    padding: 8px 8px;
  }

  .gb-btn-chip {
    width: 22px;
    height: 22px;
    font-size: 11px;
  }

  .flow-overlay {
    place-items: start center;
  }

  .flow-card {
    width: min(440px, 100%);
    margin-top: 2px;
  }
}
