:root {
  --bg: #f7f3ec;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #20201d;
  --muted: #6d7069;
  --faint: #a39f95;
  --line: #e8dfd0;
  --line-strong: #d7c9b6;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #d9f0ec;
  --danger: #be123c;
  --danger-soft: #fde2e8;
  --gold: #b87514;
  --silver: #6b7280;
  --bronze: #9a4f1a;
  --shadow: 0 18px 44px rgba(35, 30, 20, .09);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  min-height: 100vh;
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, .13), transparent 26rem),
    linear-gradient(180deg, #fbf8f1 0%, var(--bg) 22rem, #f4efe6 100%);
  color: var(--ink);
  line-height: 1.65;
}

a {
  color: inherit;
}

header {
  position: relative;
  isolation: isolate;
  min-height: 96px;
  padding: 20px 24px;
  overflow: hidden;
  color: #fffdf8;
  background: #29322d;
}

header::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background-image:
    linear-gradient(90deg, rgba(20, 31, 25, .92) 0%, rgba(20, 31, 25, .76) 48%, rgba(20, 31, 25, .38) 100%),
    url("https://commons.wikimedia.org/wiki/Special:FilePath/Brazilian%20jiu%20jitsu%20foto%201.jpg?width=1600");
  background-size: cover;
  background-position: center center;
}

header::after {
  content: "";
  position: absolute;
  inset: auto 24px 0;
  height: 3px;
  z-index: -1;
  background: linear-gradient(90deg, var(--accent), #e0b15c, var(--danger));
  border-radius: 8px 8px 0 0;
}

header > div,
header h1,
header p {
  max-width: 1120px;
}

header h1 {
  font-size: 1.22rem;
  font-weight: 800;
  line-height: 1.2;
}

header p {
  margin-top: 4px;
  max-width: 42rem;
  color: rgba(255, 253, 248, .78);
  font-size: .82rem;
}

.home-link {
  color: inherit;
  text-decoration: none;
}

.home-link:hover {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.container {
  width: min(100%, 1120px);
  margin: 28px auto 0;
  padding: 0 20px 36px;
}

.card {
  background: var(--surface);
  border: 1px solid rgba(151, 124, 86, .18);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
}

.card.dimmed {
  opacity: .48;
  pointer-events: none;
}

.card.dimmed .tournament-actions {
  pointer-events: auto;
  opacity: 1;
}

.card h2 {
  margin-bottom: 14px;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 800;
}

.page-title {
  margin-top: 0;
  color: var(--ink);
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.25;
}

.page-sub {
  margin: 8px 0 24px;
  color: var(--muted);
  font-size: .88rem;
}

label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  font: inherit;
  font-size: .95rem;
}

input:focus,
select:focus {
  outline: 3px solid rgba(15, 118, 110, .18);
  border-color: var(--accent);
}

select:disabled,
button:disabled {
  opacity: .48;
  cursor: not-allowed;
}

button,
.go-btn,
.btn-primary {
  min-height: 40px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #fffdf8;
  cursor: pointer;
  font: inherit;
  font-size: .9rem;
  font-weight: 800;
  white-space: nowrap;
}

button:hover,
.go-btn:hover,
.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-small {
  min-height: 34px;
  padding: 6px 12px;
  font-size: .8rem;
}

.search-row,
.input-row,
.control-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.search-row input,
.input-row select {
  flex: 1;
  min-width: 0;
}

.go-btn {
  width: 100%;
  margin-top: 14px;
}

.result-list {
  display: none;
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
}

.result-item {
  min-height: 42px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: .9rem;
}

.result-item:last-child {
  border-bottom: 0;
}

.result-item:hover {
  background: var(--accent-soft);
}

.result-empty,
.empty,
.no-saved,
.loading {
  color: var(--muted);
  font-size: .88rem;
}

.result-empty,
.empty {
  padding: 20px 14px;
  text-align: center;
}

.loading {
  text-align: center;
  padding: 48px 16px;
}

.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 12px;
  border: 4px solid rgba(15, 118, 110, .16);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.tournament-item {
  display: grid;
  grid-template-columns: minmax(86px, auto) minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  min-height: 68px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
  background: #fffefa;
}

.tournament-date,
.tourney-date {
  color: var(--accent);
  font-size: .8rem;
  font-weight: 900;
  white-space: nowrap;
}

.tournament-name,
.tourney-name {
  color: var(--ink);
  font-weight: 800;
  line-height: 1.35;
}

.tournament-meta,
.tourney-stats {
  margin-top: 3px;
  color: var(--muted);
  font-size: .78rem;
}

.tournament-actions {
  display: flex;
  gap: 6px;
}

.tourney-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.tourney-name-link,
.player-link,
a.player-name {
  color: var(--ink);
  font-weight: 800;
  text-decoration: underline;
  text-decoration-color: rgba(15, 118, 110, .35);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.tourney-name-link:hover,
.player-link:hover,
a.player-name:hover {
  color: var(--accent-strong);
  text-decoration-color: currentColor;
}

.section-label,
.sub-label {
  margin: 16px 0 10px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 20px;
}

.total-stats,
.stats-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.stat-item {
  min-width: 118px;
  padding: 16px 18px;
  border: 1px solid rgba(151, 124, 86, .18);
  border-radius: 8px;
  background: #fffefa;
  text-align: center;
}

.stat-num {
  font-size: 1.82rem;
  font-weight: 900;
  line-height: 1;
}

.stat-num.total {
  color: var(--ink);
}

.stat-num.win {
  color: var(--accent);
}

.stat-num.loss {
  color: var(--danger);
}

.stat-label {
  margin-top: 5px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
}

.info-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.info-chip,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 11px;
  border: 1px solid rgba(15, 118, 110, .18);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: .82rem;
  font-weight: 800;
}

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

th {
  padding: 8px 9px;
  border-bottom: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 900;
  text-align: left;
  vertical-align: top;
}

td {
  padding: 9px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: 0;
}

.summary-table,
.history-table,
.placement-table,
.match-table {
  background: transparent;
}

.placement-rank {
  width: 1%;
  font-weight: 900;
  white-space: nowrap;
}

.placement-rank.gold {
  color: var(--gold);
}

.placement-rank.silver {
  color: var(--silver);
}

.placement-rank.bronze {
  color: var(--bronze);
}

.summary-rate {
  color: var(--accent-strong);
  font-weight: 900;
  white-space: nowrap;
}

.result-badge {
  display: inline-block;
  min-width: 2.2rem;
  padding: 3px 8px;
  border-radius: 8px;
  font-size: .74rem;
  font-weight: 900;
  text-align: center;
}

.result-badge.win {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.result-badge.loss {
  background: var(--danger-soft);
  color: var(--danger);
}

.match-id,
.category-col {
  color: var(--muted);
  font-size: .76rem;
}

.history-table .result-col,
.history-table .date-col {
  width: 1%;
  white-space: nowrap;
}

.vs-row {
  display: flex;
  gap: 7px;
  align-items: center;
  flex-wrap: wrap;
}

.vs-sep {
  color: var(--faint);
  font-size: .78rem;
  font-weight: 800;
}

.player-name {
  color: var(--ink);
  font-weight: 800;
}

.player-name.ours {
  color: var(--accent-strong);
}

.player-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 14px;
}

.pf-btn {
  min-height: 32px;
  padding: 5px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fffefa;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
}

.pf-btn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fffdf8;
}

.meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: .86rem;
}

.table-name,
.section-title {
  margin-bottom: 10px;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 900;
}

pre {
  overflow-x: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #2a2721;
  color: #fff8e8;
  font-size: .78rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.sample-cell {
  max-width: 320px;
  white-space: pre-wrap;
  word-break: break-word;
}

.site-footer {
  padding: 26px 16px 34px;
  color: var(--muted);
  font-size: .8rem;
  text-align: center;
}

.site-footer a {
  color: var(--accent-strong);
  font-weight: 800;
}

.site-footer .version {
  display: inline-block;
  margin-top: 4px;
  color: var(--faint);
  font-size: .75rem;
}

@media (max-width: 860px) {
  .summary-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  header {
    min-height: 104px;
    padding: 18px;
  }

  header::before {
    background-position: center center;
  }

  header::after {
    inset-inline: 18px;
  }

  .container {
    margin-top: 22px;
    padding-inline: 14px;
  }

  .card {
    padding: 17px;
  }

  .search-row,
  .input-row,
  .control-row {
    flex-direction: column;
  }

  .tournament-item {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .tournament-actions {
    justify-content: stretch;
  }

  .tournament-actions .btn-small {
    width: 100%;
  }

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

  .stat-item {
    min-width: 0;
    padding: 14px 10px;
  }

  .stat-num {
    font-size: 1.48rem;
  }

  table {
    font-size: .76rem;
  }

  th,
  td {
    padding: 7px 6px;
  }

  .history-table .date-col,
  .history-table .date-head {
    display: none;
  }
}
