:root {
  color-scheme: light;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --header-bg: #14161c;
  --header-fg: #ffffff;
  --text: #1c1e24;
  --text-sub: #767a85;
  --border: #e3e5ea;
  --red: #e5484d;
  --red-dark: #c5323a;
  --blue: #1e78e8;
  --blue-dark: #1560c0;
  --win: #15a36a;
  --lose: #d9363e;
  --accent: #2f6fed;
  --accent-dark: #2457c2;
  --danger: #d9363e;
  --danger-dark: #b3272e;
  --radius: 16px;
  --tab-bar-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input {
  font-family: inherit;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--header-bg);
  color: var(--header-fg);
  padding: calc(14px + var(--safe-top)) 20px 14px;
  text-align: center;
}

.app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

main {
  flex: 1;
  padding: 16px 16px calc(var(--tab-bar-height) + var(--safe-bottom) + 24px);
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
}

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

/* ---- サマリーカード ---- */
.summary-card {
  background: var(--header-bg);
  color: #fff;
  border-radius: var(--radius);
  padding: 22px 20px 20px;
  text-align: center;
  margin-bottom: 20px;
}

.summary-label {
  font-size: 0.78rem;
  color: #b7bac4;
  margin-bottom: 4px;
}

.summary-points {
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.summary-points.positive { color: #3ddc84; }
.summary-points.negative { color: #ff6b6f; }

.summary-delta {
  margin-top: 4px;
  font-size: 1.3rem;
  font-weight: 600;
  color: #9a9dab;
}

.summary-delta.positive { color: #3ddc84; }
.summary-delta.negative { color: #ff6b6f; }

.summary-sub {
  margin-top: 6px;
  font-size: 0.92rem;
  color: #d4d6dd;
}

/* ---- フォーム ---- */
.field-group {
  margin-bottom: 18px;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-sub);
  margin-bottom: 8px;
  font-weight: 600;
}

.choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.choice-btn {
  appearance: none;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 14px;
  padding: 16px 8px;
  font-size: 1.05rem;
  font-weight: 700;
  min-height: 56px;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.choice-btn:active {
  transform: scale(0.97);
}

.choice-btn.color-btn.red.selected {
  background: var(--red);
  border-color: var(--red-dark);
  color: #fff;
}

.choice-btn.color-btn.blue.selected {
  background: var(--blue);
  border-color: var(--blue-dark);
  color: #fff;
}

.choice-btn.result-btn.win.selected {
  background: var(--win);
  border-color: #0f7d50;
  color: #fff;
}

.choice-btn.result-btn.lose.selected {
  background: var(--lose);
  border-color: var(--danger-dark);
  color: #fff;
}

.point-input {
  width: 100%;
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  padding: 14px 10px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}

.point-input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: -6px 0 14px;
  font-weight: 600;
}

.submit-btn {
  width: 100%;
  min-height: 58px;
  border: none;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: background 0.15s ease, transform 0.08s ease;
}

.submit-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.submit-btn:disabled {
  background: #c7cad2;
  color: #fff;
}

/* ---- 記録リスト ---- */
.section-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-sub);
  margin: 22px 0 10px;
}

.record-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.record-item {
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 14px;
  border-left: 5px solid var(--border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.record-item.red { border-left-color: var(--red); }
.record-item.blue { border-left-color: var(--blue); }

.record-main {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.record-color-badge {
  font-size: 1rem;
}

.record-point {
  font-size: 1.05rem;
  min-width: 70px;
}

.record-point.positive { color: var(--win); }
.record-point.negative { color: var(--lose); }

.record-result {
  margin-left: auto;
  font-size: 0.9rem;
  color: var(--text-sub);
  font-weight: 600;
}

.record-sub {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--text-sub);
}

.record-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.icon-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 10px;
  padding: 9px 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.icon-btn.delete {
  color: var(--danger);
  border-color: #f3c6c8;
  background: #fdf1f2;
}

.empty-message {
  text-align: center;
  color: var(--text-sub);
  font-size: 0.88rem;
  padding: 24px 0;
}

/* ---- 集計タブ ---- */
.stats-overall {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px 16px;
  margin-bottom: 8px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}

.stat-row:last-child { border-bottom: none; }
.stat-row span { color: var(--text-sub); }
.stat-row strong { font-size: 1rem; }

.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  background: var(--surface);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.stats-table th, .stats-table td {
  padding: 12px 10px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.stats-table td:first-child {
  text-align: left;
  color: var(--text-sub);
  font-weight: 600;
}

.stats-table tr:last-child td { border-bottom: none; }

/* ---- 設定タブ ---- */
.backup-desc, .backup-note {
  font-size: 0.86rem;
  color: var(--text-sub);
  line-height: 1.5;
}

.backup-note { margin-top: 10px; }

.action-btn {
  width: 100%;
  min-height: 52px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  margin: 14px 0 4px;
}

.action-btn.danger {
  background: var(--danger);
}

.action-btn:active {
  transform: scale(0.98);
}

/* ---- タブバー ---- */
.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tab-bar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 5;
}

.tab-btn {
  border: none;
  background: none;
  color: var(--text-sub);
  font-size: 0.82rem;
  font-weight: 600;
}

.tab-btn.active {
  color: var(--accent);
}

/* ---- トースト ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-bar-height) + var(--safe-bottom) + 16px);
  transform: translateX(-50%) translateY(8px);
  background: rgba(20, 22, 28, 0.92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 20;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- モーダル ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 30;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--surface);
  border-radius: 18px;
  padding: 22px 20px;
  width: 100%;
  max-width: 360px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-title {
  margin: 0 0 14px;
  font-size: 1.08rem;
  font-weight: 700;
}

.modal-desc {
  font-size: 0.9rem;
  color: var(--text-sub);
  line-height: 1.5;
  margin: 0 0 10px;
}

.modal-desc.warn {
  color: var(--danger);
  font-weight: 600;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.modal-btn {
  flex: 1;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 700;
}

.modal-btn.cancel {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.modal-btn.primary {
  background: var(--accent);
  color: #fff;
}

.modal-btn.danger {
  background: var(--danger);
  color: #fff;
}
