:root {
  --bg: #f3f5f2;
  --panel: #ffffff;
  --ink: #172128;
  --muted: #63717a;
  --line: #d8ded8;
  --blue: #245fbd;
  --green: #16745f;
  --red: #b5483f;
  --amber: #a86618;
  --teal: #256e73;
  --cream: #fbfaf4;
  --shadow: 0 10px 26px rgba(22, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 14px/1.45 Aptos, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #e9eee9;
}

.brand {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 64px;
}

.brand-mark {
  width: 56px;
  height: 56px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 16px;
}

.workspace {
  min-width: 0;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 10px;
}

.app-status {
  min-height: 36px;
  margin-bottom: 18px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--cream);
  color: var(--muted);
  font-weight: 650;
}

.app-status[data-tone="success"] {
  border-color: rgba(20, 128, 94, 0.35);
  background: #eef8f3;
  color: var(--green);
}

.app-status[data-tone="error"] {
  border-color: rgba(185, 64, 58, 0.35);
  background: #fff2f1;
  color: var(--red);
}

.status-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-pills span {
  min-width: 92px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  text-align: center;
  font-weight: 700;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 14px;
}

.panel {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel.compact {
  box-shadow: none;
}

.auth-panel {
  gap: 8px;
}

.panel.wide {
  grid-column: 1 / -1;
  overflow-x: auto;
}

.panel-header,
.button-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.invite-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 82px;
  gap: 8px;
  align-items: start;
  margin-top: 8px;
}

.full-button {
  width: 100%;
  margin-top: 8px;
}

.stacked-row {
  margin-top: 8px;
}

.compact-field {
  width: auto;
  min-width: 140px;
  margin: 0;
}

.field {
  width: 100%;
  height: 38px;
  margin: 6px 0 12px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

label {
  display: block;
  color: var(--muted);
  font-weight: 650;
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 11px;
  cursor: pointer;
  font-weight: 750;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.primary-button {
  background: var(--teal);
  color: #fff;
}

.secondary-button,
.icon-button {
  border-color: var(--line);
  background: var(--cream);
  color: var(--ink);
}

.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled),
.icon-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.pet-panel {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.pet-visual {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfd;
}

.pet-visual img {
  width: min(140px, 100%);
  height: auto;
}

.pet-visual img.sprite-atlas {
  width: 192px;
  height: 208px;
  object-fit: none;
  object-position: left top;
  transform: scale(0.72);
  transform-origin: center;
}

.stat-list {
  display: grid;
  gap: 8px;
}

.profile-summary,
.matchmaking-cards,
.admin-subgrid {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.profile-summary {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.profile-summary > div,
.status-card,
.admin-block {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfaf4;
}

.status-card {
  border-left: 3px solid var(--teal);
}

.profile-summary strong,
.status-card > strong,
.admin-block > strong {
  display: block;
  margin-bottom: 4px;
}

.profile-summary span,
.status-card span,
.timeline-meta {
  color: var(--muted);
  font-size: 12px;
}

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

.skill-alias-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.skill-alias-row .field {
  margin: 0;
}

.stat-row,
.meter-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) 72px;
  gap: 10px;
  align-items: center;
}

.bar {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: #e5e9f0;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.battle-state {
  display: grid;
  gap: 10px;
  margin: 12px 0;
}

.battle-arena {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid #cdd8d3;
  border-radius: 8px;
  background: #f7f6ec;
}

.battle-arena[data-status="finished"] {
  background: #f3f8f5;
}

.battle-combatants {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
}

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

.timeline-item {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fbfd;
}

.timeline-item > div:first-child,
.status-card > div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.status-card > div b {
  text-align: right;
}

.battle-side {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 12px;
  border: 1px solid #cfd9d5;
  border-radius: 8px;
  background: #fff;
  box-shadow: inset 0 2px 0 rgba(37, 110, 115, 0.08);
}

.battle-pet-visual {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 82px;
  padding: 8px;
  border: 1px solid #e1e6df;
  border-radius: 6px;
  background: #f9fbfd;
}

.battle-pet-visual img {
  width: 64px;
  height: 70px;
  object-fit: contain;
}

.battle-pet-visual img.sprite-atlas {
  width: 64px;
  height: 70px;
  object-fit: none;
  object-position: left top;
}

.battle-asset-meta {
  display: grid;
  gap: 3px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.battle-asset-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battle-side.is-you {
  border-color: rgba(37, 110, 115, 0.5);
}

.battle-side-header,
.turn-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.battle-side-header strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.element-chip,
.battle-meta {
  color: var(--muted);
  font-size: 12px;
}

.element-chip {
  flex: none;
  padding: 3px 7px;
  border-radius: 999px;
  background: #edf3f1;
  color: var(--teal);
  font-weight: 750;
}

.hp-bar span {
  background: var(--red);
}

.battle-vitals {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.vital-chip {
  display: grid;
  gap: 2px;
  min-height: 44px;
  min-width: 0;
  padding: 7px;
  border: 1px solid #e2e6df;
  border-radius: 6px;
  background: #fbfaf4;
}

.vital-chip b {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.vital-chip span {
  min-width: 0;
  font-weight: 750;
}

.energy-pips {
  display: flex;
  gap: 3px;
  align-items: center;
  min-height: 16px;
}

.energy-pips i {
  width: 8px;
  height: 14px;
  border-radius: 999px;
  background: #d9ded7;
}

.energy-pips i[data-on="true"] {
  background: var(--amber);
}

.battle-skill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.battle-skill-row span {
  max-width: 100%;
  padding: 3px 7px;
  overflow: hidden;
  border: 1px solid #e1e6df;
  border-radius: 999px;
  background: #f6f8f4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battle-center {
  display: grid;
  place-items: center;
  gap: 8px;
  min-width: 0;
  padding: 12px 8px;
  border: 1px solid #cfd9d5;
  border-radius: 8px;
  background: #172128;
  color: #fff;
  text-align: center;
}

.battle-mode-chip,
.pending-chip,
.battle-result-chip {
  max-width: 100%;
  padding: 4px 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #e6ece8;
  font-size: 12px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battle-turn {
  font-size: 18px;
}

.battle-countdown {
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: #256e73;
  color: #fff;
  font-weight: 850;
}

.battle-countdown[data-urgent="true"] {
  border-color: rgba(255, 204, 128, 0.8);
  background: #9c3f35;
}

.pending-chip.ready {
  background: rgba(67, 176, 130, 0.22);
  color: #d9f5e9;
}

.battle-command-bar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid #d9dfd8;
  border-radius: 6px;
  background: #fff;
}

.battle-command-bar span {
  color: var(--muted);
  text-align: right;
}

.turn-line {
  min-height: 34px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #eef2f6;
}

.subtle-line {
  background: #f9fbfd;
}

.result-line {
  border: 1px solid rgba(20, 128, 94, 0.24);
  background: #eef8f3;
}

.meter-stack {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.signal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.signal-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  color: var(--ink);
  font-weight: 600;
}

.output {
  overflow: auto;
  min-height: 112px;
  max-height: 220px;
  margin: 12px 0 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101820;
  color: #e8edf5;
  white-space: pre-wrap;
}

.compact-output {
  min-height: 70px;
  max-height: 120px;
}

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

table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  margin-top: 10px;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.event-log {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.event-item,
.review-item {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.review-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.ops-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.admin-subgrid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 12px;
}

.ops-summary > div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fbfd;
}

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

.empty-state,
.empty-cell {
  color: var(--muted);
  font-weight: 650;
}

.empty-state {
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: #f9fbfd;
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .grid,
  .pet-panel,
  .battle-combatants,
  .action-grid,
  .invite-row,
  .skill-alias-row,
  .profile-summary,
  .admin-subgrid {
    grid-template-columns: 1fr;
  }

  .ops-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .battle-center {
    order: -1;
  }

  .battle-command-bar {
    display: grid;
  }

  .battle-command-bar span {
    text-align: left;
  }
}

@media (max-width: 520px) {
  .ops-summary {
    grid-template-columns: 1fr;
  }

  .battle-vitals {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
