* { box-sizing: border-box; }

:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #f59e0b;
  --accent-2: #38bdf8;
  --win: #22c55e;
  --draw: #eab308;
  --loss: #ef4444;
  --border: #334155;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* --- Auth screen ------------------------------------------------------- */

.auth-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-screen[style*="flex"] { display: flex !important; }

.auth-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 26px;
  max-width: 400px;
  width: 100%;
}

.auth-brand {
  text-align: center;
  margin-bottom: 22px;
}
.auth-brand img {
  display: block;
  margin: 0 auto 10px;
  border-radius: 14px;
}
.auth-brand h1 {
  margin: 0 0 4px;
  font-size: 1.4rem;
}
.auth-brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 8px;
  margin-bottom: 18px;
}
.auth-tabs button {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
.auth-tabs button.active {
  background: var(--panel-2);
  color: var(--text);
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#auth-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}
#auth-form input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
}
#auth-form input:focus {
  outline: none;
  border-color: var(--accent);
}
#auth-form .hint {
  color: var(--muted);
  font-size: 0.75rem;
}
.auth-error {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-email {
  font-size: 0.8rem;
  color: var(--muted);
}

.settings-user {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  color: var(--muted);
}
.settings-user b { color: var(--text); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-ghost:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.modal-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

header {
  background: var(--panel);
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

header h1 {
  margin: 0;
  font-size: 1.4rem;
}

.icon-btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
}
.icon-btn:hover { background: var(--accent); color: #0f172a; border-color: var(--accent); }

nav {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

nav button {
  background: var(--panel-2);
  color: var(--text);
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

nav button.active {
  background: var(--accent);
  color: #0f172a;
  font-weight: 600;
}

.matchday-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}

.matchday-nav button {
  background: var(--panel-2);
  color: var(--text);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
}

#md-label {
  font-weight: 600;
  min-width: 150px;
  text-align: center;
}

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
}

.view { display: none; }
.view.active { display: block; }

.matches { display: grid; gap: 12px; }

.match {
  background: var(--panel);
  border-radius: 10px;
  padding: 14px 16px;
  border: 1px solid var(--border);
}

.match-date {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.match-teams {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
}

.team {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.team-away {
  justify-content: flex-end;
  flex-direction: row-reverse;
}

.team-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}

.team-name { font-weight: 500; }

.team-form {
  display: inline-flex;
  gap: 2px;
  margin-left: 4px;
}

.form-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.form-W { background: var(--win); }
.form-D { background: var(--draw); }
.form-L { background: var(--loss); }

.match-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 170px;
}

.match-result {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  min-height: 1.2em;
}

.match-result.pending {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 400;
}

.match-tip { display: flex; align-items: center; gap: 4px; }

.match-tip input {
  width: 40px;
  padding: 4px 6px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: center;
  font-size: 0.95rem;
}

.match-tip.correct input { border-color: var(--win); }
.match-tip.tendency input { border-color: var(--draw); }
.match-tip.wrong input    { border-color: var(--loss); }

.suggest-row {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
}

.suggest-row button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
}

.suggest-row button:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
}
.suggest-row button:disabled { opacity: 0.6; cursor: wait; }

.suggestion {
  font-size: 0.8rem;
  color: var(--accent);
  min-height: 1em;
  text-align: center;
}

.claude-response {
  display: none;
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border-left: 3px solid var(--accent-2);
  border-radius: 4px;
  font-size: 0.85rem;
  white-space: pre-wrap;
  line-height: 1.5;
}
.claude-response.show { display: block; }

.apply-claude-tip {
  margin-top: 8px;
  background: var(--accent-2);
  color: #0f172a;
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}

.match-analysis { margin-top: 10px; font-size: 0.85rem; }
.match-analysis summary { cursor: pointer; color: var(--muted); }

.analysis-content {
  margin-top: 8px;
  padding: 10px;
  background: var(--bg);
  border-radius: 6px;
  line-height: 1.5;
}

.analysis-content .stat-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.analysis-content .stat-label { color: var(--muted); }

.analysis-content h4 {
  margin: 10px 0 4px;
  font-size: 0.9rem;
  color: var(--accent);
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border-radius: 10px;
  overflow: hidden;
}

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

.table th {
  background: var(--panel-2);
  font-size: 0.85rem;
  color: var(--muted);
}

.table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.stats {
  background: var(--panel);
  padding: 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 16px;
}

.stats .stat-box { text-align: center; }

.stats .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
}

.stats .stat-label { font-size: 0.85rem; color: var(--muted); }

.history { display: grid; gap: 8px; }

.history-item {
  background: var(--panel);
  padding: 10px 14px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-left: 4px solid var(--muted);
}

.history-item.correct  { border-left-color: var(--win); }
.history-item.tendency { border-left-color: var(--draw); }
.history-item.wrong    { border-left-color: var(--loss); }

.history-item .teams { flex: 1; }
.history-item .score { font-weight: 600; color: var(--accent); }
.history-item .points {
  background: var(--panel-2);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.85rem;
}

.loading { text-align: center; padding: 40px; color: var(--muted); }

.backtest h2 { margin-top: 0; }
.backtest h3 { margin-top: 24px; color: var(--accent-2); font-size: 1.05rem; }
.backtest .panel {
  background: var(--panel);
  padding: 14px 16px;
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}
.backtest .panel p { margin: 6px 0; }
.muted { color: var(--muted); font-size: 0.9rem; }

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.open { display: flex; }

.modal-content {
  background: var(--panel);
  border-radius: 12px;
  padding: 0;
  max-width: 480px;
  width: 100%;
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }

.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
  color: var(--muted);
}
.modal-body input, .modal-body select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.95rem;
  font-family: inherit;
}
.modal-body small { color: var(--muted); font-size: 0.8rem; }

.modal-footer { padding: 14px 18px; border-top: 1px solid var(--border); text-align: right; }

.btn-primary {
  background: var(--accent);
  color: #0f172a;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

@media (max-width: 600px) {
  header h1 { font-size: 1.1rem; }
  .match-teams { grid-template-columns: 1fr; gap: 8px; }
  .team-away { flex-direction: row; justify-content: flex-start; }
  .team-name { font-size: 0.9rem; }
  .user-email { display: none; }
  main { padding: 12px; }
  .suggest-row button { padding: 6px 10px; }
  .match-tip input { width: 44px; padding: 6px 8px; font-size: 1rem; }
}
