:root {
  color-scheme: light;
  --bg: #f4efe6;
  --bg-accent: #e6dcc8;
  --surface: rgba(255, 252, 247, 0.92);
  --surface-strong: #fffaf2;
  --text: #22201d;
  --muted: #6a6259;
  --line: rgba(68, 53, 38, 0.16);
  --primary: #0f766e;
  --primary-strong: #115e59;
  --danger: #b42318;
  --success: #166534;
  --shadow: 0 22px 50px rgba(70, 54, 37, 0.14);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.15), transparent 30%),
    radial-gradient(circle at bottom right, rgba(180, 35, 24, 0.12), transparent 28%),
    linear-gradient(160deg, var(--bg), var(--bg-accent));
}

.app-shell {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

.hero {
  padding: 1.5rem 0 1rem;
}

.eyebrow {
  margin: 0 0 0.4rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--primary-strong);
  font-size: 0.78rem;
  font-weight: 700;
}

.hero h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.2rem, 5vw, 4rem);
  line-height: 0.95;
}

.hero-copy {
  max-width: 44rem;
  margin: 0.9rem 0 0;
  color: var(--muted);
  font-size: 1rem;
}

.app-card {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  padding: 1.35rem;
}

.view-header,
.section-title,
.results-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.section-title h2,
.results-header h2,
.view-header h2 {
  margin: 0;
  font-size: 1.45rem;
}

.muted {
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 1rem;
}

.panel {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.span-4 {
  grid-column: span 4;
}

.span-6 {
  grid-column: span 6;
}

.span-8 {
  grid-column: span 8;
}

.span-12 {
  grid-column: 1 / -1;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: inherit;
  padding: 0.8rem 0.9rem;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
}

textarea {
  min-height: 8rem;
  resize: vertical;
}

.field-hint {
  margin-top: 0.45rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.button-row,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 0.78rem 1.15rem;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, background 140ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.button-primary {
  background: var(--primary);
  color: #fff;
}

.button-secondary {
  background: #ebe4d8;
  color: var(--text);
}

.button-danger {
  background: #fde7e5;
  color: var(--danger);
}

.status-banner {
  border-radius: var(--radius-md);
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

.status-error {
  background: #fff7e8;
  color: #9a6700;
  border: 1px solid rgba(154, 103, 0, 0.18);
}

.status-success {
  background: #effcf3;
  color: var(--success);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
}

.stat {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0.95rem 1rem;
}

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

.stat-value {
  display: block;
  margin-top: 0.28rem;
  font-size: 1.45rem;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

th,
td {
  padding: 0.85rem 0.9rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

thead th {
  background: #f8f3ea;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

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

.table-input {
  min-width: 5.2rem;
}

.name-cell {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 13rem;
}

.name-input {
  min-width: 9rem;
}

.saved-name {
  display: inline-flex;
  align-items: center;
  min-height: 2.6rem;
  font-weight: 600;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f5efe5;
  color: var(--text);
  padding: 0;
  font-size: 1rem;
}

.icon-button:hover {
  background: #ebe2d4;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3rem;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  background: #eef7f6;
  color: var(--primary-strong);
  font-weight: 700;
}

.leaderboard {
  display: grid;
  gap: 0.75rem;
}

.leader-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-strong);
}

.leader-card.is-winner {
  border-color: rgba(15, 118, 110, 0.35);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.12), transparent),
    var(--surface-strong);
}

.rank-badge {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #ebe4d8;
  font-weight: 700;
}

.winner-flag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--success);
  font-weight: 700;
}

.breakdown-list {
  display: grid;
  gap: 0.8rem;
}

.breakdown-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0.95rem;
  background: #fff;
}

.empty-state {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 1rem, 1120px);
    padding-top: 1rem;
  }

  .app-card {
    padding: 1rem;
  }

  .span-4,
  .span-6,
  .span-8 {
    grid-column: 1 / -1;
  }

  table {
    min-width: 620px;
  }
}
