:root {
  --ink: #17212b;
  --muted: #65717d;
  --line: #d8dee3;
  --paper: #ffffff;
  --bg: #eef1f3;
  --accent: #cf3c31;
  --accent2: #f1b13a;
  --ok: #227c5b;
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgb(238 241 243 / 92%), rgb(238 241 243 / 96%)),
    repeating-linear-gradient(135deg, #ffffff 0 18px, #edf0f2 18px 36px);
}

.login-card {
  width: min(420px, 100%);
  padding: 30px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-top: 5px solid var(--accent2);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgb(23 33 43 / 14%);
}

.login-logo {
  display: block;
  width: 150px;
  height: 150px;
  object-fit: contain;
  margin: 0 auto 10px;
}

.login-card h1 {
  margin: 0;
  text-align: center;
  font-size: 26px;
}

.login-card > p {
  margin: 8px 0 24px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  line-height: 1.7;
}

.login-card label {
  display: block;
  margin-top: 14px;
  font-size: 13px;
  font-weight: 700;
}

.login-card input {
  display: block;
  width: 100%;
  height: 44px;
  margin-top: 7px;
  padding: 0 12px;
  border: 1px solid #bac3ca;
  border-radius: 4px;
}

.login-card input:focus,
.name-grid input:focus,
.character-panel select:focus {
  border-color: var(--accent);
  outline: 2px solid rgb(207 60 49 / 14%);
}

.login-message {
  min-height: 20px;
  margin: 12px 0 4px !important;
  color: var(--accent) !important;
  text-align: left !important;
}

.login-button {
  margin-top: 4px;
}

.login-card small {
  display: block;
  margin-top: 13px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.topbar {
  min-height: 58px;
  background: #17212b;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 26px;
  border-bottom: 4px solid var(--accent2);
}

.brand,
.topbar-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
}

.brand img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  background: #fff;
  border-radius: 3px;
}

.brand strong {
  font-size: 20px;
}

.brand span {
  color: #ccd3d9;
  font-size: 13px;
}

.topbar-actions {
  gap: 10px;
  font-size: 13px;
}

.text-button,
.icon-button {
  min-height: 36px;
  border: 1px solid #52606c;
  background: transparent;
  color: #fff;
  border-radius: 4px;
}

.text-button {
  padding: 0 12px;
}

.icon-button {
  width: 36px;
  font-size: 22px;
}

.app-shell {
  max-width: 1240px;
  margin: 24px auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 18px;
  padding: 0 18px;
}

.editor,
.summary {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.editor {
  padding: 24px;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 0 0 14px;
}

.section-head h1,
.section-head h2 {
  margin: 0;
  font-size: 20px;
}

.step {
  margin: 0;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
}

.type-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.type-option {
  min-height: 92px;
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  text-align: left;
}

.type-option strong {
  font-size: 18px;
}

.type-option span {
  grid-column: 1;
  color: var(--muted);
  font-size: 13px;
}

.type-option b {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: center;
  color: var(--accent);
}

.type-option.active {
  border-color: var(--accent);
  background: #fff8f6;
}

.names-head {
  margin-top: 28px;
}

.name-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 28px;
}

.name-grid label {
  font-size: 13px;
  font-weight: 700;
}

.name-grid input {
  display: block;
  width: 100%;
  height: 42px;
  margin-top: 7px;
  padding: 0 11px;
  border: 1px solid #bac3ca;
  border-radius: 4px;
}

.band {
  padding: 17px 0;
  border-top: 1px solid var(--line);
}

.stat-section h3,
.enhancement h3 {
  margin: 0;
  font-size: 15px;
}

.stat-section > p,
.enhancement p {
  margin: 4px 0 14px;
  color: var(--muted);
  font-size: 12px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 22px;
}

.stat-row {
  min-height: 40px;
  display: grid;
  grid-template-columns: 92px minmax(80px, 1fr) 76px 58px;
  gap: 9px;
  align-items: center;
}

.stat-row label {
  font-size: 13px;
}

.stat-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.stat-row input[type="number"] {
  width: 76px;
  height: 32px;
  padding: 0 7px;
  border: 1px solid #bac3ca;
  border-radius: 4px;
  text-align: right;
}

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

.enhancement {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
}

.enhance-options {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.enhance-options button {
  height: 38px;
  padding: 0 12px;
  background: #fff;
  border: 1px solid #b9c1c8;
  border-radius: 4px;
}

.enhance-options button.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.summary {
  position: sticky;
  top: 18px;
  height: max-content;
  padding: 22px;
}

.character-panel {
  display: grid;
  gap: 5px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.character-panel small,
.character-panel label {
  color: var(--muted);
  font-size: 12px;
}

.character-panel strong {
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}

.character-panel select {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  background: #fff;
  border: 1px solid #bac3ca;
  border-radius: 4px;
}

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

.budget {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 2px 0 8px;
}

.budget strong {
  font-size: 44px;
  line-height: 1;
}

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

.budget-bar {
  height: 8px;
  overflow: hidden;
  background: #e7eaed;
  border-radius: 2px;
}

.budget-bar i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.15s;
}

.usage {
  display: flex;
  justify-content: space-between;
  margin: 8px 0 20px;
  font-size: 12px;
}

.summary-names {
  display: grid;
  gap: 3px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.summary-names small {
  margin-top: 6px;
  color: var(--muted);
}

.summary-names strong {
  overflow-wrap: anywhere;
}

.allocation-list {
  min-height: 100px;
  padding: 12px 0;
  font-size: 13px;
}

.allocation-list p {
  color: var(--muted);
}

.allocation-list div {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}

.fixed-price {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.fixed-price strong {
  color: var(--accent);
  font-size: 18px;
}

.validation {
  min-height: 20px;
  color: var(--accent);
  font-size: 12px;
}

.primary {
  width: 100%;
  min-height: 44px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 4px;
  font-weight: 800;
}

.primary:disabled {
  background: #aab1b7;
  cursor: not-allowed;
}

dialog {
  width: min(620px, calc(100% - 28px));
  max-height: 90vh;
  padding: 26px;
  border: 0;
  border-radius: 7px;
  box-shadow: 0 20px 70px #0007;
}

dialog::backdrop {
  background: #111a;
}

.dialog-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: transparent;
  border: 0;
  font-size: 25px;
}

.dialog-title {
  margin: 0 0 6px;
  font-size: 22px;
}

.dialog-note {
  color: var(--muted);
  font-size: 13px;
}

.result-table {
  width: 100%;
  margin: 18px 0;
  border-collapse: collapse;
}

.result-table td {
  padding: 8px 2px;
  border-bottom: 1px solid var(--line);
}

.result-table td:last-child {
  text-align: right;
  font-weight: 700;
}

.result-table .price-row td {
  color: var(--accent);
  font-size: 18px;
  font-weight: 800;
}

.dialog-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.dialog-actions button {
  min-height: 42px;
  padding: 0 16px;
  background: #fff;
  border: 1px solid #aeb7be;
  border-radius: 4px;
  font-weight: 700;
}

.dialog-actions .primary {
  width: auto;
  margin-left: auto;
  background: var(--accent);
  border: 0;
}

.success {
  padding-left: 14px;
  border-left: 5px solid var(--ok);
}

.success h2 {
  color: var(--ok);
}

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

  .summary {
    position: static;
    order: -1;
  }

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

@media (max-width: 580px) {
  .login-screen {
    padding: 12px;
  }

  .login-card {
    padding: 22px 18px;
  }

  .login-logo {
    width: 120px;
    height: 120px;
  }

  .topbar {
    padding: 8px 12px;
  }

  .brand span,
  #loginIdentity {
    display: none;
  }

  .app-shell {
    margin: 12px auto;
    padding: 0 10px;
  }

  .editor {
    padding: 16px;
  }

  .type-switch,
  .name-grid {
    grid-template-columns: 1fr;
  }

  .stat-row {
    grid-template-columns: 82px minmax(65px, 1fr) 68px 48px;
    gap: 6px;
  }

  .stat-row input[type="number"] {
    width: 68px;
  }

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

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

  .dialog-actions .primary {
    width: 100%;
    margin: 0;
  }
}
