:root {
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
  color: #111827;
  background: #f3f4f6;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 20rem;
  min-height: 100vh;
  margin: 0;
  background: #f3f4f6;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  width: min(96vw, 90rem);
  margin: 0 auto;
  padding: 1.5rem 0;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 1rem;
}

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

h1 {
  margin-bottom: 0.25rem;
  font-size: 1.75rem;
}

.app-header p,
.panel-header p {
  margin-bottom: 0;
  color: #4b5563;
}

.status-list {
  display: flex;
  gap: 0.5rem;
}

.status-list span {
  padding: 0.3rem 0.5rem;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  color: #4b5563;
  background: #ffffff;
  font-size: 0.8rem;
}

.status-list span[data-state="ready"] {
  border-color: #86efac;
  color: #166534;
  background: #f0fdf4;
}

.status-list span[data-state="error"] {
  border-color: #fca5a5;
  color: #991b1b;
  background: #fef2f2;
}

.room-invite {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) minmax(20rem, 2fr);
  gap: 1.5rem;
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid #93c5fd;
  border-radius: 0.35rem;
  background: #eff6ff;
}

.room-invite[hidden] {
  display: none;
}

.room-invite h2,
.room-invite p {
  margin-bottom: 0;
}

.room-invite p {
  color: #4b5563;
  font-size: 0.8rem;
}

.invite-copy > div {
  display: flex;
  gap: 0.5rem;
}

.invite-copy input {
  min-width: 0;
  flex: 1;
  padding: 0.45rem 0.55rem;
  border: 1px solid #9ca3af;
  border-radius: 0.25rem;
  color: #374151;
  background: #ffffff;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.75rem;
}

.invite-copy [data-invite-feedback] {
  min-height: 1rem;
  margin-top: 0.25rem;
  color: #166534;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(22rem, 2fr);
  gap: 1rem;
}

.panel {
  min-width: 0;
  padding: 1rem;
  border: 1px solid #d1d5db;
  border-radius: 0.35rem;
  background: #ffffff;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  min-height: 2.75rem;
  margin-bottom: 0.75rem;
}

h2 {
  margin-bottom: 0.2rem;
  font-size: 1.1rem;
}

.panel-header p,
label,
.shortcut,
.code-status,
.app-footer {
  font-size: 0.8rem;
}

.telemetry {
  display: grid;
  gap: 0.35rem;
  min-width: 22rem;
}

.telemetry-tick {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  margin: 0;
}

.telemetry-tick span,
.telemetry thead th {
  color: #6b7280;
  font-size: 0.75rem;
  font-weight: 600;
}

.telemetry-tick strong,
.telemetry td {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.75rem;
}

.telemetry table {
  border-collapse: collapse;
  font-size: 0.75rem;
}

.telemetry th,
.telemetry td {
  padding: 0.1rem 0.35rem;
  text-align: right;
}

.telemetry th:first-child {
  padding-left: 0;
  text-align: left;
}

.telemetry th:last-child,
.telemetry td:last-child {
  padding-right: 0;
}

.unit-key {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  margin: 0 0.25rem 0 0.5rem;
  border-radius: 50%;
  vertical-align: -0.05rem;
}

.unit-key:first-child {
  margin-left: 0;
}

.unit-key.own {
  background: #2563eb;
}

.unit-key.opponent {
  background: #dc2626;
}

.unit-key.mine {
  border: 1px solid #92400e;
  border-radius: 0.1rem;
  background: #fde68a;
  transform: rotate(45deg);
}

.canvas-container {
  position: relative;
  overflow: hidden;
  border: 1px solid #9ca3af;
  background: #ffffff;
}

[data-game-canvas] {
  display: block;
  width: 100%;
  aspect-ratio: 12 / 7;
}

.game-result {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.25rem;
  color: #ffffff;
  background: rgb(17 24 39 / 72%);
  text-align: center;
}

.game-result[hidden] {
  display: none;
}

.game-result strong {
  font-size: clamp(1.75rem, 5vw, 3rem);
}

.game-result span {
  font-size: 0.9rem;
}

.code-panel {
  display: flex;
  flex-direction: column;
}

.legacy-code-editor[hidden] {
  display: none;
}

.strategy-builder {
  display: grid;
  gap: 0.85rem;
}

.builder-introduction,
.strategy-builder-toolbar,
.strategy-role-header,
.behavior-lane-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.builder-introduction {
  padding: 0.65rem 0.75rem;
  border: 1px solid #c4b5fd;
  border-radius: 0.3rem;
  background: #f5f3ff;
}

.builder-introduction h3,
.builder-introduction p {
  margin-bottom: 0;
}

.builder-introduction h3 {
  font-size: 0.9rem;
}

.builder-introduction p {
  margin-top: 0.15rem;
  color: #5b556d;
  font-size: 0.75rem;
}

.builder-introduction > span {
  flex: 0 0 auto;
  padding: 0.2rem 0.4rem;
  border-radius: 999px;
  color: #5b21b6;
  background: #ede9fe;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.strategy-builder-toolbar {
  align-items: flex-end;
}

.strategy-builder-toolbar label {
  min-width: 0;
  flex: 1;
  margin: 0;
}

.strategy-builder input,
.strategy-builder select {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.4rem 0.45rem;
  border: 1px solid #9ca3af;
  border-radius: 0.25rem;
  color: #111827;
  background: #ffffff;
}

.strategy-builder input:focus,
.strategy-builder select:focus {
  border-color: #2563eb;
  outline: 2px solid rgb(37 99 235 / 20%);
  outline-offset: 1px;
}

[data-strategy-roles] {
  display: grid;
  gap: 0.75rem;
}

.strategy-role-card {
  overflow: hidden;
  border: 1px solid #cbd5e1;
  border-radius: 0.35rem;
  background: #f8fafc;
}

.strategy-role-header {
  align-items: flex-end;
  padding: 0.65rem;
  border-bottom: 1px solid #e2e8f0;
  background: #ffffff;
}

.priority-badge {
  align-self: center;
  padding: 0.25rem 0.45rem;
  border-radius: 999px;
  color: #1e40af;
  background: #dbeafe;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}

.strategy-role-identity {
  display: grid;
  min-width: 0;
  flex: 1;
  grid-template-columns: minmax(8rem, 2fr) minmax(6.5rem, 1fr);
  gap: 0.5rem;
}

.strategy-role-identity label {
  margin: 0;
}

.priority-actions,
.behavior-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

button.compact-button {
  min-width: 2.1rem;
  min-height: 2.1rem;
  padding: 0.3rem 0.5rem;
}

button.small-button {
  min-height: 1.8rem;
  padding: 0.3rem 0.5rem;
  font-size: 0.72rem;
}

button.danger-button {
  color: #b91c1c;
}

.role-priority-note {
  margin: 0;
  padding: 0.45rem 0.65rem 0;
  color: #64748b;
  font-size: 0.72rem;
}

.behavior-lanes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  padding: 0.65rem;
}

.behavior-lane {
  min-width: 0;
  padding: 0.55rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.3rem;
  background: #ffffff;
}

.behavior-lane-heading {
  margin-bottom: 0.45rem;
}

.behavior-lane-heading h4 {
  margin: 0;
  font-size: 0.78rem;
}

.behavior-lane-heading span {
  color: #64748b;
  font-size: 0.65rem;
  text-transform: uppercase;
}

.behavior-item {
  margin-bottom: 0.45rem;
  padding: 0.5rem;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  background: #f9fafb;
}

.behavior-item > header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.behavior-item strong {
  font-size: 0.76rem;
}

.behavior-priority {
  display: inline-flex;
  width: 1.25rem;
  height: 1.25rem;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #ffffff;
  background: #475569;
  font-size: 0.68rem;
  font-weight: 700;
}

.behavior-item > p,
.behavior-empty {
  margin: 0.3rem 0 0.45rem;
  color: #64748b;
  font-size: 0.7rem;
  line-height: 1.35;
}

.behavior-setting {
  display: block;
  margin: 0 0 0.5rem;
  color: #374151;
  font-size: 0.7rem;
}

.behavior-setting input {
  max-width: 6rem;
}

.behavior-actions {
  flex-wrap: wrap;
}

.behavior-picker {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.behavior-picker select {
  min-width: 0;
  margin: 0;
  font-size: 0.7rem;
}

.builder-empty-state {
  margin: 0;
  padding: 1rem;
  border: 1px dashed #cbd5e1;
  border-radius: 0.3rem;
  color: #64748b;
  background: #f8fafc;
  font-size: 0.78rem;
  text-align: center;
}

.builder-action-area {
  display: grid;
  gap: 0.5rem;
  padding: 0.65rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.3rem;
  background: #f8fafc;
}

.builder-action-controls button {
  min-height: 2rem;
  padding: 0.35rem 0.55rem;
  font-size: 0.78rem;
}

.builder-action-statuses {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.builder-action-status {
  min-height: 2.1rem;
  margin: 0;
  padding: 0.5rem 0.6rem;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  color: #4b5563;
  background: #f9fafb;
  font-size: 0.72rem;
}

.builder-action-status[data-state="ready"] {
  border-color: #86efac;
  color: #166534;
  background: #f0fdf4;
}

.builder-action-status[data-state="warning"] {
  border-color: #fbbf24;
  color: #92400e;
  background: #fffbeb;
}

.simulation-controls {
  flex-wrap: wrap;
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.builder-action-statuses .code-status {
  min-height: 2.1rem;
  margin: 0;
  padding: 0.5rem 0.6rem;
  font-size: 0.72rem;
}

.matchup-picker {
  margin-bottom: 0.8rem;
  padding: 0.65rem;
  border: 1px solid #bfdbfe;
  border-radius: 0.25rem;
  background: #eff6ff;
}

.matchup-picker[hidden] {
  display: none;
}

.matchup-picker h3 {
  margin-bottom: 0.15rem;
  font-size: 0.85rem;
}

.matchup-picker p {
  margin-bottom: 0.55rem;
  color: #4b5563;
  font-size: 0.75rem;
}

.matchup-selectors {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.matchup-selectors label {
  margin: 0;
}

.matchup-selectors select {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.35rem 0.4rem;
  border: 1px solid #93c5fd;
  border-radius: 0.25rem;
  color: #111827;
  background: #ffffff;
  font-size: 0.75rem;
}

.matchup-selectors select:focus {
  border-color: #2563eb;
  outline: 2px solid rgb(37 99 235 / 20%);
  outline-offset: 1px;
}

.matchup-selectors select:disabled {
  color: #9ca3af;
  background: #f3f4f6;
}

label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

textarea {
  width: 100%;
  min-height: 17rem;
  resize: vertical;
  padding: 0.75rem;
  border: 1px solid #9ca3af;
  border-radius: 0.25rem;
  color: #111827;
  background: #ffffff;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  tab-size: 2;
}

textarea:focus {
  border-color: #2563eb;
  outline: 2px solid rgb(37 99 235 / 20%);
  outline-offset: 1px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

button {
  min-height: 2.1rem;
  padding: 0.4rem 0.8rem;
  border: 1px solid #1d4ed8;
  border-radius: 0.25rem;
  color: #ffffff;
  background: #2563eb;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #1d4ed8;
}

button:disabled {
  border-color: #d1d5db;
  color: #9ca3af;
  background: #e5e7eb;
  cursor: not-allowed;
}

button.secondary {
  border-color: #9ca3af;
  color: #111827;
  background: #ffffff;
}

button.secondary:hover:not(:disabled) {
  background: #f3f4f6;
}

button.secondary[aria-pressed="true"] {
  border-color: #2563eb;
  color: #1d4ed8;
  background: #eff6ff;
}

.shortcut {
  margin-left: auto;
  color: #6b7280;
}

.code-status {
  min-height: 2.25rem;
  margin: 0.75rem 0;
  padding: 0.55rem 0.65rem;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  color: #4b5563;
  background: #f9fafb;
}

.code-status[data-state="ready"] {
  border-color: #86efac;
  color: #166534;
  background: #f0fdf4;
}

.code-status[data-state="error"] {
  border-color: #fca5a5;
  color: #991b1b;
  background: #fef2f2;
}

.output-panel {
  min-height: 9rem;
  margin-top: auto;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  background: #f9fafb;
}

.output-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid #d1d5db;
}

.output-panel h3 {
  margin: 0;
  font-size: 0.8rem;
}

button.text-button {
  min-height: auto;
  padding: 0;
  border: 0;
  color: #4b5563;
  background: transparent;
  font-size: 0.75rem;
}

button.text-button:hover:not(:disabled) {
  color: #111827;
  background: transparent;
  text-decoration: underline;
}

[data-output] {
  max-height: 10rem;
  margin: 0;
  padding: 0.6rem 0.75rem 0.6rem 2rem;
  overflow: auto;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.75rem;
  line-height: 1.5;
}

[data-output]:empty::before {
  color: #9ca3af;
  content: "No output.";
}

[data-output] li[data-kind="error"] {
  color: #b91c1c;
}

[data-output] li[data-kind="system"] {
  color: #4b5563;
}

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.25rem 0;
  color: #6b7280;
}

code {
  font-family: Consolas, "Courier New", monospace;
}

@media (max-width: 54rem) {
  .room-invite {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  textarea {
    min-height: 13rem;
  }

  .behavior-lanes {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 36rem) {
  .app-shell {
    width: min(94vw, 90rem);
    padding-top: 1rem;
  }

  .app-header,
  .panel-header,
  .app-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-list {
    flex-wrap: wrap;
  }

  .telemetry {
    min-width: 0;
    width: 100%;
  }

  .telemetry-tick {
    justify-content: flex-start;
  }

  .controls {
    flex-wrap: wrap;
  }

  .builder-introduction,
  .strategy-builder-toolbar,
  .strategy-role-header {
    align-items: stretch;
    flex-direction: column;
  }

  .strategy-role-identity,
  .behavior-picker {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .priority-actions,
  .behavior-actions {
    flex-wrap: wrap;
  }

  .builder-action-statuses {
    grid-template-columns: 1fr;
  }

  .invite-copy > div {
    align-items: stretch;
    flex-direction: column;
  }

  .matchup-selectors {
    grid-template-columns: 1fr;
  }

  .shortcut {
    width: 100%;
    margin: 0.25rem 0 0;
  }
}
