:root {
  color-scheme: light;
  --bg: #f5f7f2;
  --surface: #ffffff;
  --text: #15201d;
  --muted: #65716c;
  --line: #dce4de;
  --ink: #111816;
  --green: #1f9d55;
  --pink: #e6467a;
  --cyan: #0088a8;
  --yellow: #f2c94c;
  --shadow: 0 10px 28px rgba(20, 31, 28, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 14px 124px;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--cyan);
  font-size: 0.75rem;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 1.75rem;
  line-height: 1.1;
}

.today-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 8px 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.header-actions {
  display: grid;
  justify-items: end;
  gap: 8px;
  min-width: 0;
}

.account-chip {
  display: grid;
  justify-items: end;
  gap: 5px;
  max-width: 180px;
}

.account-chip span {
  max-width: 100%;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-chip button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  padding: 5px 9px;
  font-size: 0.75rem;
  font-weight: 800;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.section-head {
  margin-bottom: 14px;
}

.section-head h2 {
  font-size: 1.25rem;
}

.section-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.input-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.mode-button,
.nav-button,
.primary-button,
.secondary-button,
.card-button {
  border: 0;
  cursor: pointer;
  font-weight: 800;
}

.mode-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

.mode-button.active {
  border-color: var(--ink);
  background: var(--ink);
  color: #ffffff;
}

.notice {
  margin-bottom: 12px;
  border-left: 5px solid var(--yellow);
  border-radius: 8px;
  background: #fff7d6;
  padding: 12px;
  color: #5f4b00;
  font-size: 0.9rem;
}

.ocr-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px;
}

.ocr-panel[hidden] {
  display: none;
}

.ocr-upload {
  display: grid;
  gap: 7px;
}

.ocr-camera {
  display: grid;
  gap: 10px;
}

.ocr-camera-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101615;
}

.ocr-camera-video {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.ocr-camera-guide {
  position: absolute;
  inset: 0 30%;
  border: 3px solid rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  box-shadow:
    0 0 0 999px rgba(0, 0, 0, 0.28),
    inset 0 0 0 1px rgba(21, 32, 29, 0.45);
  pointer-events: none;
}

.ocr-camera-video[hidden] + .ocr-camera-guide {
  display: none;
}

.ocr-camera-frame[data-crop-mode="portraitTight"] .ocr-camera-guide {
  inset: 0 36%;
}

.ocr-camera-frame[data-crop-mode="center2"] .ocr-camera-guide {
  inset: 25%;
}

.ocr-camera-frame[data-crop-mode="center3"] .ocr-camera-guide {
  inset: 33%;
}

.ocr-camera-frame[data-crop-mode="full"] .ocr-camera-guide {
  inset: 5%;
}

.ocr-camera-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ocr-camera-zoom {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.ocr-camera-zoom span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.ocr-upload span,
.ocr-raw summary {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.ocr-preview-wrap {
  position: relative;
}

.ocr-preview {
  width: 100%;
  max-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
  background: #fbfcfb;
  cursor: crosshair;
}

.ocr-point-marker {
  position: absolute;
  width: 24px;
  height: 24px;
  border: 3px solid var(--pink);
  border-radius: 999px;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.ocr-point-marker.self-row {
  border-color: var(--yellow);
}

.ocr-hint {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.weapon-match-result {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 10px;
}

.weapon-match-result > span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.weapon-match-list {
  display: grid;
  gap: 8px;
}

.weapon-match-button {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 6px 8px;
  cursor: pointer;
  text-align: left;
}

.weapon-match-button img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.weapon-match-button strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
}

.weapon-match-button small {
  color: var(--cyan);
  font-size: 0.78rem;
  font-weight: 800;
}

.ocr-progress {
  width: 100%;
  accent-color: var(--cyan);
}

.ocr-raw {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.ocr-raw pre {
  max-height: 180px;
  overflow: auto;
  margin: 8px 0 0;
  border-radius: 8px;
  background: #f3f6f3;
  padding: 10px;
  color: var(--text);
  font-size: 0.78rem;
  white-space: pre-wrap;
}

.auth-screen {
  display: block;
}

.auth-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 14px;
}

.auth-card label {
  display: grid;
  gap: 7px;
}

.auth-card label span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.text-button {
  justify-self: stretch;
  min-height: 42px;
  border: 1px solid #b8dfe7;
  border-radius: 8px;
  background: #eaf9fc;
  color: #00677d;
  padding: 8px 10px;
  font-size: 0.9rem;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55);
  cursor: pointer;
}

.text-button:hover,
.text-button:focus-visible {
  border-color: var(--cyan);
  background: #dff5fa;
}

.quiet-button {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.quiet-button:hover,
.quiet-button:focus-visible {
  border-color: var(--line);
  background: #f8faf8;
}

.auth-message {
  min-height: 1.4em;
  color: var(--muted);
  font-size: 0.86rem;
}

.battle-form,
.season-xpower-form {
  display: grid;
  gap: 12px;
}

fieldset,
.battle-form label,
.season-xpower-form > label,
.xpower-rule-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

fieldset {
  margin: 0;
  padding: 12px;
}

legend,
.battle-form label span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.result-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.result-toggle label {
  position: relative;
  display: block;
  box-shadow: none;
}

.result-toggle input {
  position: absolute;
  opacity: 0;
}

.result-toggle span {
  display: grid;
  min-height: 46px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
}

.result-toggle input:checked + span {
  border-color: var(--cyan);
  background: #e6f8fc;
  color: #00677d;
}

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

.form-grid label {
  min-width: 0;
}

.form-grid label:last-child:nth-child(odd) {
  grid-column: auto;
}

.battle-form label,
.season-xpower-form > label {
  display: grid;
  gap: 7px;
  padding: 10px 12px;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--text);
  padding: 8px 10px;
  font-size: 1rem;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

.battle-form .checkbox-field {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  min-height: 64px;
}

.checkbox-field input {
  flex: 0 0 auto;
  width: 22px;
  min-height: 22px;
}

.checkbox-field span {
  color: var(--text);
  font-size: 0.95rem;
  white-space: nowrap;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.form-message {
  min-height: 1.4em;
  color: var(--muted);
  font-size: 0.86rem;
}

.primary-button,
.secondary-button {
  min-height: 50px;
  border-radius: 8px;
}

.primary-button {
  background: var(--pink);
  color: #ffffff;
  box-shadow: var(--shadow);
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}

.list-filters,
.analysis-controls,
.battle-list,
.analysis-content {
  display: grid;
  gap: 12px;
}

.list-filters,
.analysis-controls {
  grid-template-columns: 1fr 1fr;
  align-items: end;
  margin-bottom: 12px;
}

.list-filters label,
.analysis-controls label {
  display: grid;
  gap: 6px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px;
  box-shadow: var(--shadow);
}

.filter-reset-button {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-weight: 800;
}

.list-filters span,
.analysis-controls span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.battle-card,
.summary-panel,
.stats-panel,
.rate-panel,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.battle-card {
  padding: 13px;
}

.battle-card.win {
  border-left: 6px solid var(--green);
}

.battle-card.lose {
  border-left: 6px solid var(--pink);
}

.card-top,
.kd-line,
.rate-panel li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.result-badge {
  border-radius: 999px;
  background: var(--ink);
  color: #ffffff;
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.battle-card.win .result-badge {
  border: 1px solid #9ed9b8;
  background: #e8f7ee;
  color: #137344;
}

.battle-card.lose .result-badge {
  border: 1px solid #f0aec4;
  background: #fff0f5;
  color: #b72d5b;
}

.date-text,
.kd-line span,
.rate-panel small {
  color: var(--muted);
  font-size: 0.84rem;
}

.kd-line {
  margin: 12px 0;
}

.kd-line strong {
  font-size: 1.3rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 0;
}

.meta-grid div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

dd {
  margin: 0;
  text-align: right;
  font-weight: 700;
}

.memo-text {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

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

.card-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--cyan);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(0, 136, 168, 0.16);
}

.card-button.danger {
  border: 1px solid #f3b2c7;
  background: #fff3f7;
  color: var(--pink);
  box-shadow: none;
}

.summary-panel {
  display: grid;
  gap: 4px;
  padding: 16px;
  background: var(--ink);
  color: #ffffff;
}

.summary-panel span,
.summary-panel small {
  color: #c8d4cf;
}

.summary-panel strong {
  font-size: 2.5rem;
  line-height: 1;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  overflow: hidden;
  background: var(--line);
}

.stats-panel div {
  display: grid;
  gap: 5px;
  min-width: 0;
  background: var(--surface);
  padding: 13px 8px;
  text-align: center;
}

.stats-panel span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.stats-panel strong {
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1;
}

.rate-panel {
  padding: 14px;
}

.rate-panel h3,
.xpower-trend-panel h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}

.rate-panel ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rate-panel li {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.rate-panel li span {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.rate-panel li strong {
  margin-left: auto;
  color: var(--cyan);
}

.xpower-trend-panel {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 14px;
}

.xpower-trend-rule {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.xpower-trend-rule h4 {
  margin: 0;
  font-size: 0.95rem;
}

.xpower-trend-table {
  display: grid;
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.xpower-trend-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr 0.9fr;
  gap: 1px;
  background: var(--line);
}

.xpower-trend-row span,
.xpower-trend-row strong {
  min-width: 0;
  background: var(--surface);
  padding: 8px 5px;
  font-size: 0.74rem;
  text-align: right;
}

.xpower-trend-row span:first-child {
  text-align: left;
}

.xpower-trend-row.header span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.xpower-trend-row .positive {
  color: var(--green);
  font-weight: 800;
}

.xpower-trend-row .negative {
  color: var(--pink);
  font-weight: 800;
}

.season-xpower-fields {
  display: grid;
  gap: 14px;
}

.xpower-rule-panel {
  display: grid;
  gap: 12px;
  padding: 14px 12px;
}

.xpower-rule-panel h3 {
  font-size: 1rem;
  line-height: 1.2;
}

.xpower-input-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
}

.xpower-input-grid label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.xpower-input-grid input {
  text-align: right;
}

.xpower-input-grid span,
.season-xpower-form > label span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.empty-state {
  display: grid;
  gap: 6px;
  padding: 18px;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: min(100%, 520px);
  margin: 0 auto;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}

.nav-button {
  min-height: 48px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.nav-button.active {
  background: var(--cyan);
  color: #ffffff;
}

@media (min-width: 480px) {
  .app-shell {
    padding-inline: 20px;
  }

  .stats-panel {
    grid-template-columns: repeat(4, 1fr);
  }
}
