:root {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #111827;
  background: #f9fafb;
  font-synthesis: none;
  --line: #e5e7eb;
  --blue: #25668a;
  --red: #934b42;
}
* { box-sizing: border-box; }
body { margin: 0; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button, a, summary { touch-action: manipulation; }
button, summary { cursor: pointer; }
button { border: 0; }
button:disabled { cursor: default; opacity: .5; }
a { color: inherit; }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid #2563eb; outline-offset: 3px; }
input:focus-visible, select:focus-visible { outline: 2px solid #2563eb; outline-offset: 1px; }
input[type=checkbox] { accent-color: #2563eb; width: 16px; height: 16px; flex-shrink: 0; }
h1, h2, h3, p { margin-top: 0; }
main { max-width: 1180px; margin: 0 auto; padding: 24px 24px 48px; }
.masthead { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px max(24px, calc((100vw - 1132px)/2)); background: #fff; border-bottom: 1px solid var(--line); }
.masthead h1 { margin: 0; font-size: 20px; font-weight: 600; }
.brand { text-decoration: none; }
#account { display: flex; align-items: center; gap: 18px; font-size: 13px; }
.quiet { color: #374151; border: 1px solid #d1d5db; border-radius: 6px; padding: 8px 14px; background: #fff; font-size: 13px; }
.quiet:hover { background: #f3f4f6; }
.primary { background: #2563eb; color: #fff; padding: 12px 24px; border-radius: 6px; font-size: 14px; font-weight: 500; }
.primary:hover { background: #1d4ed8; }
.toolbar { display: flex; justify-content: flex-end; margin-bottom: 16px; }
.forces { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.force { background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.force-heading { display: flex; align-items: center; gap: 12px; background: #edf4f7; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.side-1 .force-heading { background: #f6eeeb; }
.side-tag { font-size: 11px; font-weight: 700; color: #fff; background: var(--blue); border-radius: 4px; width: 26px; height: 26px; display: grid; place-items: center; }
.side-1 .side-tag { background: var(--red); }
.side-name { font-size: 18px; font-weight: 600; background: transparent; border: 0; width: 100%; min-width: 20px; color: var(--blue); padding: 2px; }
.side-1 .side-name { color: var(--red); }
.count { font-size: 12px; white-space: nowrap; color: #6b7280; }
.piece { padding: 20px; border-bottom: 1px solid var(--line); }
.piece-info { display: flex; gap: 12px; align-items: center; }
.piece-symbol { font-family: 'Segoe UI Symbol', serif; color: var(--blue); font-size: 39px; width: 38px; text-align: center; flex-shrink: 0; }
.side-1 .piece-symbol { color: var(--red); }
.piece-fields { flex: 1; min-width: 0; }
.piece-fields select { border: 1px solid #d1d5db; border-radius: 5px; padding: 6px 8px; background: #fff; color: #111827; width: 100%; font-size: 14px; }
.piece-name { background: transparent; border: 0; border-bottom: 1px solid var(--line); padding: 5px 1px; color: #4b5563; width: 100%; font-size: 12px; margin-top: 3px; }
.piece-name::placeholder { color: #9ca3af; }
.piece-stats { font-family: ui-monospace, Consolas, monospace; font-size: 10px; color: #6b7280; white-space: nowrap; }
.remove { font-size: 23px; color: #9ca3af; background: transparent; padding: 5px; }
.remove:hover { color: #b91c1c; }
.upgrades { margin-top: 12px; font-size: 12px; }
.upgrades summary { color: #4b5563; line-height: 1.6; padding: 3px 0; }
.upgrades[open] summary { margin-bottom: 12px; }
.upgrade-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.upgrade-option { display: flex; align-items: center; gap: 7px; padding: 6px; border-radius: 4px; background: #f9fafb; font-size: 12px; min-width: 0; }
.add-piece { margin: 16px 20px 10px; padding: 11px 14px; width: calc(100% - 40px); background: #fff; border: 1px dashed #d1d5db; color: #374151; border-radius: 5px; font-size: 12px; }
.add-piece:hover { background: #f9fafb; }
.lance-support { display: flex; align-items: center; gap: 8px; padding: 5px 20px 16px; font-size: 12px; color: #4b5563; }
.calculate-panel { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-top: 24px; }
#status { font-size: 13px; color: #6b7280; }
.calculate-panel .primary { min-width: 150px; }
.error { font-size: 13px; color: #b91c1c; line-height: 1.5; }
.error:empty { display: none; }
#error { margin: 16px 0; }
.results-heading { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin: 32px 0 16px; }
.results-heading h2 { font-size: 20px; font-weight: 600; margin: 0; }
.method { font-size: 12px; color: #6b7280; }
.win-cards, .survival-tables { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.win-card { padding: 24px; border: 1px solid #cbdce4; border-radius: 8px; background: #eaf2f6; color: var(--blue); }
.win-card.side-1 { background: #f6eae5; color: var(--red); border-color: #e6d5ce; }
.win-card p { font-size: 13px; margin-bottom: 10px; }
.win-card strong { font-size: 40px; font-weight: 600; display: block; letter-spacing: -1px; font-variant-numeric: tabular-nums; }
.win-card>span { font-size: 12px; display: block; margin-top: 6px; }
.survival-tables { margin-top: 24px; }
.survival-card { padding: 23px; background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: auto; }
.survival-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
thead th { font-weight: 500; color: #6b7280; font-size: 12px; padding-bottom: 10px; }
th { text-align: left; }
td, thead th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
tbody th { font-weight: 400; max-width: 180px; overflow-wrap: anywhere; }
td { font-weight: 600; white-space: nowrap; }
tbody th, td { padding: 11px 0; border-top: 1px solid var(--line); }
.table-symbol { font-size: 24px; vertical-align: middle; margin-right: 9px; }
.draw { text-align: center; margin: 16px 0; font-size: 12px; color: #6b7280; }
.login-page .masthead, .calculator-page #login { display: none; }
.login-page main { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 0; }
.login { max-width: 448px; width: 100%; padding: 32px; }
.login-heading { text-align: center; margin-bottom: 32px; }
.login h1 { font-size: 36px; line-height: 40px; font-weight: 700; margin: 0 0 8px; }
.login-heading p { color: #4b5563; font-size: 16px; line-height: 24px; margin: 0; }
.discord-button { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; padding: 12px 16px; border: 1px solid #d1d5db; border-radius: 8px; box-shadow: 0 1px 2px #0000000d; background: #5865f2; color: #fff; font-size: 16px; line-height: 24px; font-weight: 500; text-decoration: none; }
.discord-button:hover { background: #4752c4; }
.discord-button svg { width: 20px; height: 20px; flex-shrink: 0; }
.login .error { margin: 16px 0 0; text-align: center; }
@media (max-width: 900px) {
  .piece { padding: 16px; }
  .piece-info { gap: 8px; }
  .piece-stats { font-size: 9px; }
  .force-heading { padding: 16px; }
  .upgrade-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .masthead { padding: 16px; gap: 12px; }
  .masthead h1 { font-size: 16px; }
  #account { gap: 8px; font-size: 11px; }
  #account>span { max-width: 74px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #account .quiet { padding: 7px 9px; font-size: 11px; white-space: nowrap; }
  main { padding: 20px 16px 32px; }
  .forces { grid-template-columns: 1fr; gap: 20px; }
  .upgrade-grid { grid-template-columns: 1fr 1fr; }
  .calculate-panel { gap: 12px; }
  .results-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
  .win-cards { gap: 12px; }
  .win-card { padding: 20px 16px; }
  .win-card strong { font-size: 30px; }
  .survival-tables { grid-template-columns: 1fr; gap: 18px; }
}
@media (prefers-reduced-motion: no-preference) {
  button, a { transition: background .15s, color .15s; }
}
