:root {
  color-scheme: light;
  --bg: #f3f5f0;
  --panel: #ffffff;
  --panel-soft: #edf3f1;
  --text: #1f2524;
  --muted: #697676;
  --line: #d9e1df;
  --accent: #137c73;
  --accent-strong: #0f5f59;
  --danger: #b64c44;
  --shadow: 0 16px 34px rgba(36, 45, 43, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  padding: 0 12px;
}

button:hover {
  border-color: #94b7b2;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button.primary {
  width: 100%;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-strong);
}

.hidden {
  display: none !important;
}

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

h1 {
  font-size: 24px;
  font-weight: 780;
}

h2 {
  color: #36413f;
  font-size: 13px;
  font-weight: 760;
  margin-bottom: 12px;
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.auth-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 18px;
}

.auth-brand {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.auth-brand span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  margin-bottom: 14px;
}

.auth-tabs button {
  border: 0;
  border-radius: 0;
}

.auth-tabs button + button {
  border-left: 1px solid var(--line);
}

.auth-tabs .active {
  background: #dfeeea;
  color: var(--accent-strong);
  font-weight: 760;
}

.auth-form {
  display: grid;
  gap: 4px;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.brand,
.account-pill {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.save-state {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  padding: 0 10px;
  white-space: nowrap;
}

.save-state.saved {
  background: #e1f3ee;
  color: #14735a;
}

.save-state.error {
  background: #f7dfdc;
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(230px, 280px) minmax(420px, 1fr) minmax(260px, 310px);
  gap: 16px;
  flex: 1;
  min-height: 0;
  padding: 16px;
}

.panel {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel section {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel section:last-child {
  border-bottom: 0;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 680;
}

.field b {
  justify-self: end;
  color: var(--muted);
  font-size: 11px;
  font-weight: 680;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 9px 10px;
}

input[type="checkbox"] {
  width: auto;
  padding: 0;
}

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

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 0 10px;
  white-space: nowrap;
}

textarea {
  resize: vertical;
}

.stat-card {
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbf9;
  padding: 12px;
  margin-bottom: 12px;
}

.viewer-info {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 12px;
  margin-bottom: 12px;
}

.viewer-info strong {
  font-size: 18px;
  overflow-wrap: anywhere;
}

.viewer-info span {
  color: var(--muted);
  font-size: 12px;
}

.stat-value,
.stat-label {
  display: block;
}

.stat-value {
  font-size: 30px;
  font-weight: 800;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
}

.stage-area {
  min-width: 0;
  min-height: 0;
}

.canvas-shell {
  position: relative;
  width: 100%;
  min-width: 0;
  height: calc(100vh - 104px);
  min-height: 560px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf8;
  box-shadow: var(--shadow);
}

#avatarCanvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#avatarCanvas.dragging {
  cursor: grabbing;
}

.model-status {
  position: absolute;
  right: 12px;
  bottom: 12px;
  min-width: 76px;
  border: 1px solid rgba(30, 36, 36, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: #34413f;
  font-size: 12px;
  font-weight: 760;
  padding: 7px 10px;
  text-align: center;
  pointer-events: none;
}

.button-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.button-row button {
  flex: 1 1 0;
}

.match-results {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.match-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--text);
  padding: 10px;
  text-align: left;
}

.match-item:hover {
  border-color: #94b7b2;
  background: #f5faf8;
}

.match-name {
  font-weight: 760;
  overflow-wrap: anywhere;
}

.match-meta,
.google-box {
  color: var(--muted);
  font-size: 12px;
}

.google-box {
  display: grid;
  justify-items: stretch;
  margin-bottom: 12px;
}

.match-score {
  min-width: 58px;
  border-radius: 999px;
  background: #e4efec;
  color: var(--accent-strong);
  text-align: center;
  font-weight: 800;
  padding: 6px 9px;
}

.empty-state,
.code-box {
  border: 1px dashed #c8d2d0;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  padding: 12px;
}

.code-box {
  display: grid;
  gap: 4px;
  margin-top: 12px;
}

.code-box strong {
  color: var(--text);
  font-size: 22px;
  letter-spacing: 0;
}

.error-text {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
}

@media (max-width: 1060px) {
  .workspace {
    grid-template-columns: minmax(220px, 260px) minmax(360px, 1fr);
  }

  .match-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

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

  .match-panel section:last-child {
    border-right: 0;
  }
}

@media (max-width: 760px) {
  .topbar,
  .brand,
  .account-pill {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    gap: 10px;
    min-height: 0;
    padding: 10px;
  }

  .brand,
  .account-pill {
    flex-direction: row;
    justify-content: space-between;
  }

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

  .stage-area {
    order: 1;
  }

  .account-panel {
    order: 2;
  }

  .match-panel {
    display: block;
    order: 3;
  }

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

  .canvas-shell {
    height: min(68vh, 640px);
    min-height: 520px;
  }
}
