@font-face {
  font-family: Inter;
  src: url('/static/fonts/inter-regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: Inter;
  src: url('/static/fonts/inter-semibold.ttf') format('truetype');
  font-weight: 600;
  font-display: swap;
}

@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('/static/fonts/bricolage-grotesque.ttf') format('truetype');
  font-weight: 200 800;
  font-display: swap;
}

:root {
  font-family: Inter, system-ui, sans-serif;
  color: #012447;
  background: #fff;
  font-synthesis: none;
  --brand: #3793ef;
  --brand-hover: #2478cd;
  --border: #e0e3e8;
  --muted: #6e7684;
  --subtle: #f7f8fa;
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, textarea, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button, a, textarea { transition: background-color 120ms, border-color 120ms, box-shadow 120ms; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgb(55 147 239 / 35%);
  outline-offset: 3px;
}
button:disabled { cursor: default; opacity: .45; }
::selection { color: #00041c; background: #c9e3fa; }

.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: 24px 12px;
  border-right: 1px solid var(--border);
  background: var(--subtle);
}
.sidebar-top { padding: 0 4px; }
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
  font-family: 'Bricolage Grotesque', system-ui, sans-serif;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.02em;
}
.brand svg { flex-shrink: 0; color: var(--brand); }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #012447;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
}
.button:hover:not(:disabled) { background: var(--subtle); }
.primary { color: #fff; background: var(--brand); border-color: var(--brand); }
.primary:hover:not(:disabled) { color: #fff; background: var(--brand-hover); border-color: var(--brand-hover); }
.primary:active:not(:disabled) { background: #1560ab; border-color: #1560ab; }
.new-battle { justify-content: flex-start; width: 100%; margin-top: 32px; }
.new-battle > span { font-size: 20px; font-weight: 400; }
.history { overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin-top: 20px; }
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 8px;
  text-align: left;
  color: #012447;
  background: transparent;
  font-size: 13px;
  line-height: 20px;
}
.history-item:hover { background: #eef0f3; }
.history-item.active { background: #e3f2fd; }
.history-title { overflow: hidden; flex: 1; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { width: 6px; height: 6px; flex-shrink: 0; border-radius: 50%; background: var(--brand); }
.status-dot.failed { background: #c93131; }
.rated { display: flex; align-items: center; flex-shrink: 0; gap: 4px; color: var(--brand); font-size: 12px; font-weight: 600; }
main { position: relative; min-width: 0; }

.compose { display: grid; min-height: 100dvh; padding: 48px; align-items: center; }
#prompt-form { width: 100%; max-width: 640px; margin: -64px auto 0; }
.prompt-label {
  display: block;
  margin-bottom: 24px;
  color: #00041c;
  font-family: 'Bricolage Grotesque', system-ui, sans-serif;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -.02em;
  line-height: 1.15;
}
.prompt-box { border: 1px solid var(--border); border-radius: 16px; background: #fff; box-shadow: 0 2px 6px rgb(1 36 71 / 4%); }
.prompt-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgb(55 147 239 / 35%); }
textarea {
  display: block;
  width: 100%;
  min-height: 152px;
  max-height: 360px;
  padding: 24px;
  resize: vertical;
  border: 0;
  border-radius: 16px;
  color: #012447;
  background: transparent;
  font-size: 16px;
  line-height: 1.55;
}
textarea::placeholder { color: #9a9fa8; }
textarea:focus-visible { outline: none; }
.prompt-footer { display: flex; justify-content: flex-end; padding: 0 16px 16px; }

.battle-view { max-width: 1440px; margin: 0 auto; padding: 48px; }
.battle-header { margin-bottom: 32px; }
.battle-header h1 { margin: 0; max-width: 80ch; font-size: 18px; font-weight: 600; line-height: 1.55; overflow-wrap: anywhere; white-space: pre-wrap; }
.candidates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.candidate { overflow: hidden; display: flex; flex-direction: column; min-height: min(480px, 65dvh); border: 1px solid var(--border); border-radius: 12px; }
.candidate.selected { border-color: var(--brand); box-shadow: 0 0 0 2px rgb(55 147 239 / 12%); }
.candidate-header { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; min-height: 64px; padding: 16px 20px; border-bottom: 1px solid #eef0f3; font-size: 13px; }
.saved-choice { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; color: var(--brand); font-size: 12px; font-weight: 600; white-space: nowrap; }
.build-time { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.side-label { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 5px; background: var(--subtle); font-size: 12px; font-weight: 600; }
.candidate-content { display: grid; flex: 1; min-height: 240px; padding: 32px 24px; place-items: center; }
.build-status { display: flex; flex-direction: column; align-items: center; gap: 16px; color: var(--muted); font-size: 13px; }
.spinner { display: inline-block; width: 24px; height: 24px; border: 2px solid #e3f2fd; border-top-color: var(--brand); border-radius: 50%; animation: spin 850ms linear infinite; }
.spinner.small { width: 12px; height: 12px; flex-shrink: 0; border-width: 1.5px; }
.view-app { gap: 16px; }
.view-app:hover { border-color: #c9e3fa; }
.preference { display: flex; align-items: center; gap: 8px; min-height: 56px; padding: 16px 20px; border-top: 1px solid #eef0f3; font-size: 14px; cursor: pointer; }
.preference:hover { background: var(--subtle); }
.preference input { width: 16px; height: 16px; margin: 0; accent-color: #2478cd; }
.rating-bar { display: flex; flex-direction: column; align-items: center; gap: 16px; max-width: 640px; margin: 0 auto; padding-top: 32px; }
#rating-comment { min-height: 96px; max-height: 240px; padding: 16px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
#rating-comment:focus-visible { outline: 3px solid rgb(55 147 239 / 35%); outline-offset: 3px; }
.review-comment { max-width: 640px; margin: 24px auto 0; padding-left: 16px; border-left: 2px solid var(--brand); font-size: 14px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.build-failed { max-width: 100%; text-align: center; }
.build-failed .error { max-width: 40ch; max-height: 140px; overflow: auto; margin: 0 0 16px; text-align: left; }
.error { margin: 16px 0 0; color: #c93131; font-size: 13px; line-height: 1.55; overflow-wrap: anywhere; }
.connection { position: fixed; right: 24px; bottom: 16px; margin: 0; padding: 12px 16px; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); background: #fff; font-size: 13px; }

.app-viewer { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.viewer-bar { display: flex; flex-shrink: 0; align-items: center; gap: 12px; min-height: 48px; padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--subtle); font-size: 13px; }
.viewer-bar strong { font-weight: 600; }
.viewer-frame { flex: 1; width: 100%; min-height: 0; border: 0; background: #fff; }

@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
  .spinner { animation-duration: 2s; }
}
@media (max-width: 1000px) {
  .app { grid-template-columns: 208px minmax(0, 1fr); }
  .compose, .battle-view { padding: 32px; }
  .candidates { gap: 16px; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar { position: static; height: auto; padding: 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 0; }
  .brand { font-size: 16px; }
  .brand svg { width: 18px; height: 18px; }
  .new-battle { width: auto; margin: 0; padding: 8px 12px; }
  .history { flex-direction: row; margin-top: 12px; overflow-x: auto; }
  .history:empty { display: none; }
  .history-item { width: 176px; flex-shrink: 0; padding: 8px 12px; }
  .compose { min-height: calc(100dvh - 104px); padding: 24px; }
  #prompt-form { margin-top: -32px; }
  .prompt-label { font-size: 24px; }
  .battle-view { padding: 24px; }
  .battle-header { margin-bottom: 24px; }
  .candidates { grid-template-columns: minmax(0, 1fr); }
  .candidate { min-height: 320px; }
  .candidate-content { min-height: 200px; }
}
