:root {
  --green: #1a5d3f;
  --green-dark: #134730;
  --green-light: #2d8659;
  --gold: #d4af37;
  --gold-dark: #b8941f;
  --red: #b8302b;
  --yellow: #d9a43a;
  --bg: #faf8f3;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-dim: #6b6b6b;
  --border: #e3ddd0;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
  --radius: 10px;
  --radius-sm: 6px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --college-1: #8b1a1a;
  --college-2: #1f3a5f;
  --college-3: #2d6a4f;
  --college-4: #b8941f;
  --college-5: #5a2c8a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--green);
  color: #fff;
  border-bottom: 2px solid var(--gold);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-title {
  font-family: 'Oswald', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin: 0;
  text-transform: uppercase;
}

.modal-card h2 {
  font-family: 'Oswald', -apple-system, BlinkMacSystemFont, sans-serif;
  letter-spacing: 0.03em;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: rgba(255,255,255,0.2); }
.icon-btn:active { transform: scale(0.95); }

/* Main */
.game {
  flex: 1;
  padding: 16px 16px 200px;
  max-width: 540px;
  width: 100%;
  margin: 0 auto;
}

.date-line {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Colleges */
.colleges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
}

.college-tile {
  flex: 0 1 calc((100% - 16px) / 3);
  background: color-mix(in srgb, var(--c, var(--green)) 10%, var(--surface));
  border-radius: var(--radius);
  padding: 12px 10px;
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
  border-left: 5px solid var(--c, var(--green));
  box-shadow: var(--shadow);
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Sports */
.sports {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sport-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  transition: border-color 120ms ease, opacity 200ms ease;
}

.sport-card.pending {
  opacity: 0.5;
}

.sport-card.active {
  border-color: var(--gold);
}

.sport-card.solved {
  background: var(--green);
  color: #fff;
}

.sport-card.failed {
  background: var(--red);
  color: #fff;
}

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

.sport-name {
  font-weight: 800;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.attempt-dots {
  display: flex;
  gap: 5px;
}

.attempt-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
}
.attempt-dot.used { background: var(--text-dim); }
.attempt-dot.g { background: var(--green-light); }
.attempt-dot.y { background: var(--yellow); }
.attempt-dot.r { background: var(--red); }
.sport-card.solved .attempt-dot,
.sport-card.failed .attempt-dot { background: rgba(255,255,255,0.5); }
.sport-card.solved .attempt-dot.used,
.sport-card.failed .attempt-dot.used { background: #fff; }

.guess-history {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.guess-row {
  font-size: 14px;
  padding: 4px 8px;
  background: rgba(0,0,0,0.04);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 6px;
}
.guess-row.wrong { color: var(--red); }
.guess-row.correct {
  background: rgba(45,134,89,0.15);
  color: var(--green-dark);
  font-weight: 700;
}
.sport-card.solved .guess-row,
.sport-card.failed .guess-row {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.reveal {
  margin-top: 6px;
  font-size: 13px;
  opacity: 0.9;
}

.reveal strong { font-weight: 800; }

.sport-card.shake {
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.sport-card.flip {
  animation: flip 0.4s ease-in-out;
}

@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

/* Status line */
.status {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  margin: 12px 0 0;
  min-height: 18px;
}

/* Guess bar */
.guess-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + var(--safe-bottom));
  z-index: 9;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}

.guess-bar.hidden { display: none; }

.guess-bar-inner {
  display: flex;
  gap: 8px;
  max-width: 540px;
  margin: 0 auto;
}

.autocomplete {
  flex: 1;
  position: relative;
}

.guess-input {
  width: 100%;
  font-size: 16px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  outline: none;
  font-family: inherit;
}

.guess-input:focus {
  border-color: var(--green);
  background: #fff;
}

.suggestions {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  list-style: none;
  padding: 4px;
  margin: 0;
}

.suggestions li {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 15px;
  user-select: none;
}

.suggestions li:hover,
.suggestions li[aria-selected="true"] {
  background: var(--bg);
}

.submit-btn {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0 18px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  letter-spacing: 0.02em;
}

.submit-btn:disabled {
  background: var(--border);
  color: var(--text-dim);
  cursor: not-allowed;
}

.submit-btn:not(:disabled):hover { background: var(--green-dark); }
.submit-btn:not(:disabled):active { transform: scale(0.97); }

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  animation: fade-in 0.15s ease-out;
}

.modal[hidden] { display: none; }

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--surface);
  border-radius: 14px;
  max-width: 420px;
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 24px 20px 20px;
  position: relative;
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.2s ease-out;
}

@keyframes pop-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-dim);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
}
.modal-close:hover { background: var(--bg); }

.modal-card h2 {
  margin: 0 0 12px;
  font-size: 22px;
  color: var(--green);
}

.modal-card h3 {
  margin: 16px 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.modal-card p { margin: 0 0 12px; line-height: 1.5; }

.rules {
  padding-left: 18px;
  margin: 0 0 16px;
  line-height: 1.6;
}

.rules li { margin-bottom: 4px; }

.legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg);
  padding: 12px;
  border-radius: var(--radius);
}

.legend > div {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.tile-pip {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  display: inline-block;
}
.tile-pip.g { background: var(--green-light); }
.tile-pip.y { background: var(--yellow); }
.tile-pip.r { background: var(--red); }

.emoji-grid {
  font-size: 28px;
  text-align: center;
  letter-spacing: 0.1em;
  margin: 16px 0;
}

.obscurity-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  border-radius: 999px;
  background: var(--gold);
  color: #2a1d00;
  vertical-align: middle;
}

.sport-card.solved .obscurity-badge,
.sport-card.failed .obscurity-badge {
  background: rgba(255,255,255,0.25);
  color: #fff;
}

.breakdown {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.breakdown li {
  display: grid;
  grid-template-columns: 24px 50px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.breakdown .bd-tile { font-size: 18px; }
.breakdown .bd-sport { font-weight: 700; text-transform: uppercase; font-size: 11px; letter-spacing: 0.05em; color: var(--text-dim); }
.breakdown .bd-name { font-weight: 500; }
.breakdown .obscurity-badge { margin-left: 0; }

.score-line {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 16px;
}

.streak-row {
  display: flex;
  gap: 12px;
  justify-content: space-around;
  background: var(--bg);
  padding: 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.streak-row > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.streak-row strong {
  font-size: 24px;
  color: var(--green);
}

.streak-row span {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

.primary-btn {
  display: block;
  width: 100%;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  letter-spacing: 0.02em;
}
.primary-btn:hover { background: var(--green-dark); }
.primary-btn:active { transform: scale(0.98); }

.next-puzzle {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  margin: 12px 0 0;
}

.share-status {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--green);
  margin: 10px 0 0;
}

.share-fallback {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  resize: vertical;
  background: var(--bg);
}

.histogram {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.histogram-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.histogram-row .label {
  width: 28px;
  text-align: right;
  color: var(--text-dim);
}

.histogram-row .bar {
  background: var(--green);
  color: #fff;
  padding: 2px 8px;
  border-radius: 3px;
  font-weight: 700;
  min-width: 24px;
  text-align: right;
}

.histogram-row .bar.empty {
  background: var(--border);
  color: var(--text-dim);
  min-width: 24px;
}

/* Desktop */
@media (min-width: 768px) {
  .game { padding: 24px 24px 240px; }
  .header { padding: 14px 20px; }
  .college-tile {
    flex: 0 1 calc((100% - 32px) / 5);
    font-size: 15px;
    min-height: 60px;
  }
  .guess-bar { padding-bottom: calc(20px + var(--safe-bottom)); }
}
