:root {
  color-scheme: light;
  --bg: #edf1f5;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --border: #d7dee8;
  --text: #172033;
  --muted: #667085;
  --accent: #2563eb;
  --accent-active: #1d4ed8;
  --win: #62bd85;
  --loss: #e87d86;
  --danger: #c2414d;
  --shadow: 0 8px 24px rgba(23, 32, 51, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--bg); }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; letter-spacing: 0; }
button { -webkit-tap-highlight-color: transparent; }

.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#app-shell { min-height: 100dvh; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: rgba(247, 249, 252, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand img { border-radius: 8px; box-shadow: 0 3px 10px rgba(37, 99, 235, 0.2); }
.brand h1, .brand p, .sub-header h2, .sub-header p { margin: 0; }
.brand h1 { font-size: 18px; line-height: 1.25; }
.brand p, .sub-header p { margin-top: 2px; color: var(--muted); font-size: 12px; }

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 8px;
}

.icon-button:active { background: #e5eaf1; }
.view { width: min(1180px, 100%); margin: 0 auto; padding: 14px 14px calc(34px + env(safe-area-inset-bottom)); }

.control-band {
  display: grid;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.segment {
  --segment-index: 0;
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  background: #e9eef5;
  border-radius: 8px;
}

.segment::before {
  content: "";
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 12px) / 3);
  background: var(--accent);
  border-radius: 6px;
  box-shadow: 0 2px 7px rgba(37, 99, 235, 0.22);
  transform: translateX(calc(var(--segment-index) * (100% + 3px)));
  transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

.segment button {
  position: relative;
  z-index: 1;
  min-height: 38px;
  padding: 7px 10px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
}

.segment button.is-active {
  color: #fff;
  background: transparent;
}

@media (prefers-reduced-motion: reduce) {
  .segment::before { transition: none; }
}

.control-row { display: grid; grid-template-columns: minmax(110px, 1fr) auto; gap: 10px; align-items: end; }
.count-field, .form-field { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }

input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  outline: none;
  font-size: 16px;
}

input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-weight: 700;
}

.button-primary { color: #fff; background: var(--accent); }
.button-primary:active { background: var(--accent-active); }
.button-secondary { color: var(--text); background: var(--surface); border-color: var(--border); }
.button-danger { width: 100%; margin-top: 18px; color: var(--danger); background: #fff5f5; border-color: #f5c9ce; }
.button-full { width: 100%; margin-top: 10px; }
.button svg { width: 18px; height: 18px; }

.empty-state {
  display: grid;
  min-height: 44dvh;
  place-items: center;
  align-content: center;
  gap: 14px;
  color: var(--muted);
  text-align: center;
}

.empty-state > svg { width: 50px; height: 50px; color: #94a3b8; }
.empty-state h2 { margin: 0; color: var(--text); font-size: 19px; }

.section-block { margin-top: 22px; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 3px 10px; }
.section-heading h2 { margin: 0; font-size: 18px; }
.section-heading span { color: var(--muted); font-size: 13px; }

.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.summary-card, .opening-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-card { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; min-height: 140px; padding: 16px; }
.summary-card h3 { margin: 0 0 10px; font-size: 15px; }
.summary-numbers { display: grid; gap: 5px; color: var(--muted); font-size: 13px; }
.summary-numbers strong { color: var(--text); font-weight: 700; }

.donut {
  --rate: 0;
  display: grid;
  width: 82px;
  height: 82px;
  flex: 0 0 82px;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--win) calc(var(--rate) * 1%), var(--loss) 0);
}

.donut.is-empty { background: #dfe5ec; }
.donut::after { content: ""; grid-area: 1 / 1; width: 52px; height: 52px; border-radius: 50%; background: var(--surface); }
.donut span { z-index: 1; grid-area: 1 / 1; font-size: 12px; font-weight: 800; }

.opening-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.opening-slot { min-width: 0; }
.opening-card { padding: 16px; }
.opening-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.opening-head h3 { margin: 2px 0 13px; font-size: 17px; line-height: 1.45; overflow-wrap: anywhere; }
.opening-stats { display: grid; gap: 7px; }
.stat-line { display: grid; grid-template-columns: 36px 1fr; gap: 8px; align-items: baseline; font-size: 13px; }
.stat-line > span { color: var(--muted); font-weight: 700; }
.stat-values { display: flex; flex-wrap: wrap; gap: 3px 10px; }
.stat-values strong { font-weight: 700; }
.stat-win { color: #27814b; }
.stat-loss { color: #bd4550; }
.opening-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 15px; }
.small-button { min-height: 36px; padding: 7px 11px; font-size: 13px; }
.small-button svg { width: 17px; height: 17px; }
.detail-button svg { transition: transform 180ms ease; }
.detail-button[aria-expanded="true"] svg { transform: rotate(180deg); }

.child-list { display: grid; gap: 8px; margin: 8px 0 4px 18px; padding-left: 10px; border-left: 2px solid #b9c8dc; }
.child-list[hidden] { display: none; }
.child-list .opening-card { box-shadow: none; background: #fbfcfe; }

.sub-header {
  position: sticky;
  top: 72px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 60px;
  margin: -14px -14px 12px;
  padding: 8px 12px;
  background: rgba(247, 249, 252, 0.96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}
.sub-header h2 { max-width: calc(100vw - 90px); font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.games-list { display: grid; gap: 8px; }
.game-row { display: grid; grid-template-columns: auto 1fr; gap: 9px 12px; padding: 13px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.result-dot { width: 9px; height: 9px; margin-top: 6px; border-radius: 50%; background: var(--loss); }
.game-row.is-win .result-dot { background: var(--win); }
.game-main { min-width: 0; }
.game-file { display: block; width: 100%; padding: 0; color: var(--accent); background: none; border: 0; font-weight: 700; line-height: 1.5; text-align: left; overflow-wrap: anywhere; }
.game-meta { display: flex; flex-wrap: wrap; gap: 7px 12px; margin-top: 5px; color: var(--muted); font-size: 12px; }
.no-games { padding: 44px 16px; color: var(--muted); text-align: center; }

dialog { color: var(--text); }
dialog::backdrop { background: rgba(15, 23, 42, 0.44); backdrop-filter: blur(2px); }
.modal { width: min(92vw, 430px); padding: 0; border: 0; border-radius: 8px; box-shadow: 0 24px 70px rgba(15, 23, 42, 0.25); }
.modal form { padding: 18px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin: -5px -5px 15px 0; }
.modal-header h2 { margin: 0; font-size: 19px; }
.storage-row { display: flex; justify-content: space-between; margin-top: 18px; padding: 13px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); color: var(--muted); font-size: 14px; }
.storage-row strong { color: var(--text); }

.action-sheet { width: min(100%, 520px); max-width: none; margin: auto auto 0; padding: 9px 14px calc(14px + env(safe-area-inset-bottom)); border: 0; border-radius: 8px 8px 0 0; }
.sheet-handle { width: 38px; height: 4px; margin: 0 auto 14px; border-radius: 2px; background: #cbd5e1; }
.action-sheet h2 { margin: 0 4px 12px; font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; }
.sheet-action, .sheet-cancel { display: flex; width: 100%; min-height: 50px; align-items: center; gap: 12px; padding: 10px 12px; color: var(--text); background: transparent; border: 0; border-top: 1px solid #e5e9ef; text-align: left; }
.sheet-cancel { justify-content: center; margin-top: 7px; background: #f1f4f8; border: 0; border-radius: 7px; font-weight: 700; }

.toast { position: fixed; z-index: 80; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); max-width: calc(100vw - 28px); padding: 10px 14px; color: #fff; background: #172033; border-radius: 7px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: 180ms ease; font-size: 13px; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .summary-grid { grid-template-columns: 1fr; }
  .summary-card { min-height: 120px; }
  .opening-list { grid-template-columns: 1fr; }
  .view { padding-left: 12px; padding-right: 12px; }
  .sub-header { margin-left: -12px; margin-right: -12px; }
  .opening-head .donut { width: 76px; height: 76px; flex-basis: 76px; }
  .opening-head .donut::after { width: 48px; height: 48px; }
}

@media (min-width: 761px) {
  .control-band { grid-template-columns: minmax(300px, 0.6fr) minmax(360px, 1fr); align-items: end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
