:root {
  color-scheme: dark;
  --bg: #090a0d;
  --surface: rgba(22, 20, 17, 0.96);
  --surface-2: rgba(34, 30, 24, 0.98);
  --line: rgba(220, 168, 70, 0.44);
  --line-soft: rgba(255, 255, 255, 0.10);
  --gold: #f0c266;
  --gold-2: #ffdf93;
  --amber: #c87b16;
  --text: #f7f3e9;
  --muted: #b9b2a6;
  --cyan: #67e9e6;
  --danger: #ff7676;
  --success: #8ee6ab;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% -10%, rgba(205, 143, 35, 0.18), transparent 34rem),
    radial-gradient(circle at 100% 35%, rgba(50, 123, 128, 0.10), transparent 26rem),
    linear-gradient(180deg, #11100e 0%, var(--bg) 30%, #050608 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 14px max(28px, env(safe-area-inset-bottom));
}

.hero-header {
  position: relative;
  overflow: hidden;
  padding: 24px 18px 22px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 20px;
  background:
    linear-gradient(135deg, rgba(255, 211, 117, 0.08), transparent 35%),
    linear-gradient(180deg, rgba(35, 31, 23, 0.98), rgba(12, 12, 12, 0.98));
  box-shadow: var(--shadow);
}

.hero-header::before,
.hero-header::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 72px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold));
}
.hero-header::before { left: 0; }
.hero-header::after { right: 0; transform: rotate(180deg); }

.eyebrow,
.section-kicker {
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.hero-header h1 {
  margin: 5px 0 5px;
  color: var(--gold-2);
  font-family: Georgia, "Yu Mincho", serif;
  font-size: clamp(1.85rem, 8vw, 2.8rem);
  letter-spacing: 0.04em;
  text-shadow: 0 0 22px rgba(243, 190, 78, 0.28);
}

.hero-header p { margin: 0; color: var(--muted); font-size: 0.85rem; }

.tabs {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 12px 0;
  padding: 8px;
  border: 1px solid rgba(240, 194, 102, 0.28);
  border-radius: 17px;
  background: rgba(8, 9, 11, 0.88);
  backdrop-filter: blur(16px);
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}

.tab {
  position: relative;
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 62px;
  padding: 7px 3px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab > span { font-size: 1.05rem; }
.tab strong { font-size: clamp(0.72rem, 3vw, 0.9rem); }
.tab.is-active {
  border-color: rgba(255, 220, 143, 0.75);
  background: linear-gradient(180deg, rgba(206, 137, 28, 0.95), rgba(102, 60, 8, 0.95));
  color: #fff8e5;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12), 0 5px 18px rgba(192, 112, 17, .25);
}

.saved-count {
  position: absolute;
  top: 4px;
  right: 5px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(0,0,0,.45);
  color: var(--gold-2);
  font-size: .66rem;
  line-height: 18px;
}

.panel,
.result-card {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  box-shadow: var(--shadow);
}

.panel { padding: 17px; }

.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--gold-2);
  font-weight: 800;
}

.name-row { display: grid; grid-template-columns: 1fr auto; gap: 9px; }

.text-input,
.number-input {
  width: 100%;
  border: 1px solid rgba(255,255,255,.16);
  outline: none;
  background: rgba(0,0,0,.38);
  color: var(--text);
  transition: border-color .2s, box-shadow .2s, background .2s;
}

.text-input {
  min-height: 48px;
  padding: 0 14px;
  border-radius: 12px;
}

.text-input:focus,
.number-input:focus {
  border-color: var(--gold);
  background: rgba(0,0,0,.55);
  box-shadow: 0 0 0 3px rgba(240, 194, 102, .12);
}

.edit-state { margin-top: 8px; color: var(--muted); font-size: .76rem; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 15px;
  padding-bottom: 11px;
  border-bottom: 1px solid var(--line-soft);
}

.section-heading h2,
.backup-panel h2 {
  margin: 2px 0 0;
  color: #fff2c9;
  font-size: 1.16rem;
}

.coefficient-badge,
.saved-summary,
.help-chip {
  flex: 0 0 auto;
  border: 1px solid rgba(240,194,102,.42);
  border-radius: 999px;
  background: rgba(240,194,102,.08);
  color: var(--gold-2);
  font-size: .72rem;
  font-weight: 800;
  padding: 6px 9px;
}

.help-chip { cursor: pointer; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field-grid.single { grid-template-columns: 1fr; }
.field-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.number-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  align-items: center;
  gap: 8px;
  min-height: 54px;
  padding: 9px 10px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  background: rgba(255,255,255,.025);
}

.number-field label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: #e8dfd0;
  font-weight: 750;
  font-size: .9rem;
}

.field-icon { width: 1.25em; text-align: center; filter: saturate(1.15); }
.field-coef { color: var(--gold); font-size: .67rem; font-weight: 700; }

.input-wrap { position: relative; }
.number-input {
  height: 38px;
  padding: 0 7px;
  border-radius: 9px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.number-input::-webkit-inner-spin-button,
.number-input::-webkit-outer-spin-button { opacity: .42; }

.is-hidden { display: none !important; }

.result-card {
  position: relative;
  overflow: hidden;
  padding: 22px 18px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 70%, rgba(225, 153, 39, .22), transparent 48%),
    linear-gradient(180deg, #282015, #0e0e0f 78%);
}

.result-card::before {
  content: "";
  position: absolute;
  inset: 7px;
  pointer-events: none;
  border: 1px solid rgba(255, 219, 137, .2);
  border-radius: 13px;
}

.result-label { position: relative; color: #f3e4bd; font-weight: 800; }
.result-value {
  position: relative;
  margin: 3px 0 8px;
  color: #ffdc83;
  font-family: Georgia, serif;
  font-size: clamp(4rem, 20vw, 6.5rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 12px rgba(255, 192, 62, .4), 0 0 30px rgba(255, 157, 0, .2);
}

.breakdown {
  position: relative;
  display: grid;
  gap: 6px;
  max-width: 520px;
  margin: 0 auto;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.10);
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: .82rem;
}
.breakdown-row strong { color: #fff3cf; font-variant-numeric: tabular-nums; }

.primary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 12px;
}

.button {
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 850;
  cursor: pointer;
  transition: transform .12s, filter .12s, box-shadow .12s;
}
.button:active { transform: translateY(1px) scale(.99); }
.button:hover { filter: brightness(1.08); }
.button-calc {
  background: linear-gradient(180deg, #dd981f, #9a5709);
  border-color: #ffd078;
  color: white;
  box-shadow: 0 8px 23px rgba(197, 110, 12, .28);
}
.button-save {
  background: linear-gradient(180deg, #0c918d, #075d61);
  border-color: #67e9e6;
  color: white;
  box-shadow: 0 8px 23px rgba(9, 128, 127, .22);
}
.button-reset {
  grid-column: 1 / -1;
  background: linear-gradient(180deg, #3b3d42, #24262a);
  border-color: rgba(255,255,255,.18);
  color: #ddd;
}
.button-subtle {
  background: rgba(255,255,255,.05);
  border-color: rgba(255,255,255,.15);
  color: #e7e2d8;
}

.saved-panel { padding-bottom: 10px; }
.saved-heading { margin-bottom: 9px; }
.saved-list { display: grid; gap: 9px; }

.empty-state {
  padding: 24px 10px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed rgba(255,255,255,.12);
  border-radius: 12px;
  font-size: .86rem;
}

.saved-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 13px;
  background: rgba(0,0,0,.25);
}
.saved-item.is-editing { border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(103,233,230,.08); }
.saved-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 850; }
.saved-meta { margin-top: 3px; color: var(--muted); font-size: .72rem; }
.saved-score { color: var(--gold-2); font-weight: 900; font-variant-numeric: tabular-nums; }
.saved-actions { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.saved-actions button { min-height: 38px; padding: 6px 10px; border-radius: 9px; }
.load-button { background: rgba(103,233,230,.08); border: 1px solid rgba(103,233,230,.35); color: #9ef7f4; }
.delete-button { background: rgba(255,118,118,.06); border: 1px solid rgba(255,118,118,.28); color: #ff9b9b; }

.formula-panel summary {
  cursor: pointer;
  color: var(--gold-2);
  font-weight: 850;
}
.formula-grid { display: grid; gap: 8px; margin-top: 14px; }
.formula-grid > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 11px;
  border-radius: 10px;
  background: rgba(255,255,255,.035);
}
.formula-grid span { color: var(--muted); }
.formula-grid strong { color: var(--gold-2); white-space: nowrap; }
.formula-note { margin: 12px 0 0; color: var(--muted); font-size: .79rem; line-height: 1.7; }

.backup-panel { display: grid; gap: 14px; }
.backup-panel p { margin: 7px 0 0; color: var(--muted); font-size: .8rem; line-height: 1.6; }
.backup-actions { display: grid; gap: 8px; }
.file-button { display: grid; place-items: center; }
.file-button input { display: none; }

footer { padding: 20px 8px 0; text-align: center; color: #77756f; font-size: .7rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 100;
  width: min(calc(100% - 28px), 520px);
  padding: 12px 15px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 12px;
  background: rgba(20,21,24,.96);
  color: white;
  text-align: center;
  box-shadow: 0 14px 40px rgba(0,0,0,.42);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: opacity .2s, transform .2s;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.success { border-color: rgba(142,230,171,.45); }
.toast.error { border-color: rgba(255,118,118,.55); }

.dialog {
  width: min(calc(100% - 28px), 520px);
  padding: 0;
  border: 0;
  border-radius: 17px;
  background: transparent;
  color: var(--text);
}
.dialog::backdrop { background: rgba(0,0,0,.74); backdrop-filter: blur(3px); }
.dialog-card { border: 1px solid var(--line); border-radius: 17px; background: #191714; padding: 18px; box-shadow: var(--shadow); }
.dialog-title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dialog-title-row h2 { margin: 0; color: var(--gold-2); }
.icon-button { width: 38px; height: 38px; border: 1px solid rgba(255,255,255,.15); border-radius: 50%; background: rgba(255,255,255,.05); font-size: 1.35rem; cursor: pointer; }

@media (min-width: 620px) {
  .app-shell { padding-left: 20px; padding-right: 20px; }
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .number-field { grid-template-columns: minmax(0, 1fr) 100px; }
  .backup-panel { grid-template-columns: 1fr auto; align-items: center; }
  .backup-actions { min-width: 220px; }
}

@media (max-width: 390px) {
  .app-shell { padding-left: 9px; padding-right: 9px; }
  .panel { padding: 13px; }
  .tab { min-height: 58px; }
  .number-field { grid-template-columns: minmax(0, 1fr) 72px; padding: 8px; }
  .number-field label { font-size: .82rem; }
  .field-coef { display: none; }
  .primary-actions { grid-template-columns: 1fr; }
  .button-reset { grid-column: auto; }
}

/* 武器カテゴリの時だけ表示する武器種サブメニュー */
.weapon-type-panel {
  margin-top: 0;
  padding: 14px;
  background:
    linear-gradient(135deg, rgba(240, 194, 102, .06), transparent 42%),
    linear-gradient(180deg, rgba(31, 27, 21, .98), rgba(17, 16, 15, .98));
}

.weapon-type-heading {
  margin-bottom: 11px;
  padding-bottom: 9px;
}

.weapon-type-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
}

.weapon-type-tab {
  position: relative;
  display: grid;
  place-items: center;
  gap: 2px;
  min-width: 0;
  min-height: 54px;
  padding: 7px 2px 6px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 10px;
  background: rgba(0,0,0,.24);
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .12s;
}

.weapon-type-tab:active { transform: translateY(1px); }
.weapon-type-tab strong { font-size: clamp(.66rem, 2.8vw, .82rem); white-space: nowrap; }
.weapon-type-icon { font-size: 1rem; line-height: 1; }

.weapon-type-tab.is-active {
  border-color: rgba(103,233,230,.72);
  background: linear-gradient(180deg, rgba(16, 126, 124, .55), rgba(7, 69, 73, .68));
  color: #ecffff;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08), 0 5px 16px rgba(9,128,127,.16);
}

.weapon-type-count {
  position: absolute;
  top: 3px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: rgba(0,0,0,.48);
  color: var(--gold-2);
  font-size: .58rem;
  line-height: 16px;
  text-align: center;
}

.weapon-type-note {
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: .73rem;
  line-height: 1.5;
}

/* 保存一覧は戦闘力順。順位もひと目で分かるようにする */
.saved-item {
  grid-template-columns: 31px minmax(0, 1fr) auto;
}

.saved-rank {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(240,194,102,.34);
  border-radius: 50%;
  background: rgba(240,194,102,.08);
  color: var(--gold-2);
  font-size: .75rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.saved-main { min-width: 0; }
.saved-actions { grid-column: 2 / -1; }

@media (max-width: 350px) {
  .weapon-type-tabs { gap: 5px; }
  .weapon-type-tab { min-height: 50px; }
  .weapon-type-tab strong { font-size: .62rem; }
  .weapon-type-icon { font-size: .9rem; }
}
