@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

:root {
  --bg: #ffffff;
  --fg: #000000;
  --accent: #0a7739;
  --accent-60: #0a773999;
  --gray-10: #0000001a;
  --gray-20: #00000033;
  --gray-40: #00000066;
  --gray-60: #00000099;
  --gray-70: #000000b3;
  --gray-800: #1e2939;
  --surface: #f5f6fa;
  --danger: #ba4705;
  --success: #0a7739;
}

*, *::before, *::after { box-sizing: border-box; touch-action: manipulation; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1.5;
}

#app {
  width: 100%;
  max-width: 720px;
  padding: 40px 24px;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 32px;
  border-bottom: 1px solid var(--gray-20);
  padding-bottom: 20px;
}

h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 1;
  cursor: default;
  user-select: none;
}

#status {
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--gray-20);
  padding: 6px 14px;
  text-align: center;
  line-height: 1.6;
}

/* Help button */
.btn-help {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--gray-20);
  background: transparent;
  color: var(--gray-60);
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  text-transform: none;
  letter-spacing: 0;
  transition: border-color 0.15s, color 0.15s;
}
.btn-help:hover { border-color: var(--fg); color: var(--fg); background: transparent; }

.intro-help {
  margin-top: 12px;
}

/* How to play modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fade-up 0.2s ease-out;
}

.modal-box {
  background: #fff;
  border: 1px solid var(--gray-20);
  padding: 28px 32px;
  max-width: 440px;
  width: 90%;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  font-size: 0.875rem;
  color: var(--gray-40);
  cursor: pointer;
  padding: 4px 8px;
  text-transform: none;
  letter-spacing: 0;
}
.modal-close:hover { color: var(--fg); background: transparent; }

.modal-title {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0 0 16px;
}

.modal-steps {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--gray-70);
}

.modal-ok {
  width: 100%;
  margin-top: 20px;
  padding: 12px;
  font-size: 1rem;
}

.key-inline {
  display: inline-block;
  padding: 1px 6px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
}
.correct-inline { background: #16a34a; }
.present-inline { background: #d97706; }
.wrong-inline   { background: #dc2626; }

.attempts-good   { color: var(--success); font-weight: 700; }
.attempts-warn   { color: #d97706;       font-weight: 700; }
.attempts-danger { color: var(--danger); font-weight: 700; }

.attempt-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin: 0 3px;
  vertical-align: middle;
  background: currentColor;
}
.attempt-dot.attempts-good   { color: var(--success); }
.attempt-dot.attempts-warn   { color: #d97706; }
.attempt-dot.attempts-danger { color: var(--danger); }
.attempt-dot-used {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin: 0 3px;
  vertical-align: middle;
  background: var(--gray-20);
}

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.timer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.timer {
  font-family: 'DM Mono', monospace;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: var(--gray-60);
}

.final-time {
  font-family: 'DM Mono', monospace;
  font-size: 0.875rem;
  color: var(--gray-40);
  margin-bottom: 16px;
}

.game-description {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--gray-40);
}

/* Main card */
main {
  background: var(--surface);
  padding: 32px;
  border: 1px solid var(--gray-20);
}

/* Target word */
#targetWord {
  margin: 0 0 8px 0;
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 1.15;
}

.round-label {
  font-size: 1rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: var(--fg);
  margin-bottom: 24px;
}

/* Pool */
.pool {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

/* Chips */
.chip {
  font-family: 'DM Mono', monospace;
  font-size: 0.875rem;
  font-weight: 500;
  background: #ffffff;
  color: var(--fg);
  padding: 8px 14px;
  border: 1px solid var(--gray-20);
  border-radius: 0;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.chip:hover {
  background: var(--fg);
  color: #ffffff;
  border-color: var(--fg);
}

.chip:focus {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.chip:active {
  transform: translateY(1px);
}

/* Working area */
.working {
  min-height: 52px;
  background: #ffffff;
  border: 1px solid var(--gray-20);
  padding: 8px;
  margin-bottom: 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.working .chip {
  background: var(--fg);
  color: #ffffff;
  border-color: var(--fg);
}

.working .chip:hover {
  background: var(--gray-800);
  border-color: var(--gray-800);
}

.chip[draggable] { cursor: grab; }
.chip[draggable]:active { cursor: grabbing; }

.working .chip.dragging {
  opacity: 0.35;
}

.working.drag-over {
  border-color: #4f46e5;
  border-style: dashed;
  background: #eef2ff;
}

.working .chip.drag-over {
  border-color: #4f46e5;
  border-style: dashed;
  background: #eef2ff;
  color: #4f46e5;
}

/* Feedback states — shown after an incorrect submission */
.working .chip.chip-correct {
  background: #16a34a;
  border-color: #16a34a;
  color: #ffffff;
}
.working .chip.chip-correct:hover {
  background: #15803d;
  border-color: #15803d;
}

.working .chip.chip-present {
  background: #d97706;
  border-color: #d97706;
  color: #ffffff;
}
.working .chip.chip-present:hover {
  background: #b45309;
  border-color: #b45309;
}

.working .chip.chip-wrong {
  background: #dc2626;
  border-color: #dc2626;
  color: #ffffff;
}
.working .chip.chip-wrong:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

/* Pool chip in "used/selected" state — stays visible but dimmed */
.pool .chip.chip-used {
  opacity: 0.35;
  cursor: pointer;
  text-decoration: line-through;
}
.pool .chip.chip-used:hover {
  opacity: 0.6;
  background: var(--fg);
  color: #ffffff;
}

/* Answer area placeholders */
.chip.chip-wrong-pool {
  border-color: #dc2626;
  background: rgba(220, 38, 38, 0.12);
  color: #dc2626;
  cursor: not-allowed;
  opacity: 0.8;
}
.chip.chip-wrong-pool:hover {
  border-color: #dc2626;
  background: rgba(220, 38, 38, 0.12);
  color: #dc2626;
}

.working .chip.chip-locked {
  cursor: default;
  opacity: 0.85;
}

.chip.chip-swap-selected {
  border-color: #4f46e5;
  background: rgba(79, 70, 229, 0.08);
  color: #4f46e5;
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}

.chip.chip-swap-selected:hover {
  border-color: #4f46e5;
  background: rgba(79, 70, 229, 0.14);
  color: #4f46e5;
}

.chip.chip-placeholder {
  border: 1.5px dashed rgba(79, 70, 229, 0.35);
  background: rgba(79, 70, 229, 0.04);
  color: transparent;
  cursor: default;
  min-width: 48px;
  user-select: none;
}

.chip.chip-placeholder:hover {
  border-color: rgba(79, 70, 229, 0.35);
  background: rgba(79, 70, 229, 0.04);
  color: transparent;
}

.chip.chip-placeholder.drag-over {
  border-color: rgba(79, 70, 229, 0.7);
  background: rgba(79, 70, 229, 0.08);
}

/* Controls */
.controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

button {
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--fg);
  color: #ffffff;
  border: 1px solid var(--fg);
  padding: 10px 20px;
  border-radius: 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

button:hover { background: var(--gray-800); border-color: var(--gray-800); }
button:active { transform: translateY(1px); }

button:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

/* Primary button — electric indigo */
button.btn-primary {
  background: #4f46e5;
  color: #ffffff;
  border-color: #4f46e5;
}
button.btn-primary:hover {
  background: #ffffff;
  color: #4f46e5;
  border-color: #4f46e5;
}
button.btn-primary:focus-visible {
  outline-color: #4f46e5;
}

/* Secondary button — outlined */
button.btn-secondary, a.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 20px;
  border-radius: 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--fg);
  text-decoration: none;
  line-height: 1;
}
button.btn-secondary:hover, a.btn-secondary:hover {
  background: var(--fg);
  color: #ffffff;
}

/* Start Session / Restart button in header */
header button {
  font-size: 0.75rem;
  padding: 6px 14px;
}

/* Message */
.message {
  min-height: 22px;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 8px;
}

.message.success { color: var(--success); animation: fade-up 0.3s ease-out; }
.message.error   { color: var(--danger); animation: fade-up 0.3s ease-out; }

/* Animations */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15%      { transform: translateX(-6px); }
  30%      { transform: translateX(6px); }
  45%      { transform: translateX(-4px); }
  60%      { transform: translateX(4px); }
  75%      { transform: translateX(-2px); }
  90%      { transform: translateX(2px); }
}

@keyframes pulse-danger {
  0%, 100% { border-color: var(--gray-20); box-shadow: none; }
  50%      { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(186,71,5,0.15); }
}

@keyframes pop-in {
  0%   { transform: scale(0.92); opacity: 0; }
  60%  { transform: scale(1.04); opacity: 1; }
  100% { transform: scale(1); }
}

@keyframes round-exit {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-12px); }
}

@keyframes round-enter {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

#round { position: relative; }
#round.round-exit  { animation: round-exit  0.2s ease-in forwards; pointer-events: none; }
#round.round-enter { animation: round-enter 0.25s ease-out forwards; }

@keyframes clear-flash {
  0%   { background: var(--fg); color: #fff; }
  40%  { background: var(--danger); color: #fff; border-color: var(--danger); }
  100% { background: transparent; color: var(--fg); border-color: var(--fg); }
}

button.btn-secondary.clearing {
  animation: clear-flash 0.35s ease-out forwards;
}

.working.shake {
  animation: shake 0.45s ease-out;
}

#status.pulse-danger {
  animation: pulse-danger 1s ease-in-out infinite;
}

/* Celebration state */
#round.celebrating .working {
  border-color: #16a34a;
  background: #f0fdf4;
  animation: celebrate-flash 1.8s ease-out forwards;
}

#round.celebrating #message {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

#round.celebrating #submitBtn,
#round.celebrating #clearBtn {
  opacity: 0.4;
  cursor: not-allowed;
}

@keyframes celebrate-flash {
  0%   { background: #bbf7d0; border-color: #16a34a; }
  30%  { background: #dcfce7; border-color: #16a34a; }
  100% { background: #f0fdf4; border-color: #16a34a; }
}

/* Result banner overlay */
.result-banner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px 24px;
  z-index: 20;
  animation: banner-in 0.25s ease;
  text-align: center;
}

.result-banner.hidden { display: none; }

.result-banner.banner-success {
  background: rgba(10, 119, 57, 0.97);
  color: #fff;
}

.result-banner.banner-failure {
  background: rgba(186, 71, 5, 0.97);
  color: #fff;
}

.result-banner-icon {
  font-size: 3rem;
  line-height: 1;
}

.result-banner-msg {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.result-banner-sub {
  font-size: 0.9375rem;
  opacity: 0.88;
  line-height: 1.5;
  max-width: 340px;
}

.result-banner .result-banner-btn {
  margin-top: 8px;
  background: #fff;
  color: #000;
  border-color: transparent;
}

.result-banner .result-banner-btn:hover {
  background: rgba(255, 255, 255, 0.85);
}

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

/* Intro / zero state */
/* Ad slot */
.ad-slot {
  width: 100%;
  max-width: 320px;
  height: 50px;
  margin: 24px auto 0;
  background: var(--surface);
  border: 1px dashed var(--gray-20);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-label {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-40);
  margin: 0;
}

.game-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--gray-10);
}

.footer-right { display: flex; gap: 8px; align-items: center; }

.final-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }


.btn-test {
  display: block;
  margin: 10px auto 0;
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: transparent;
  color: var(--gray-40);
  border: 1px dashed var(--gray-20);
  padding: 6px 12px;
  cursor: pointer;
  opacity: 0.6;
}
.btn-test:hover { opacity: 1; color: var(--fg); border-color: var(--fg); }

#intro {
  text-align: center;
  padding: 48px 0 24px;
}

.intro-date {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gray-40);
  margin: 20px 0 4px;
}

.intro-title {
  font-size: clamp(2rem, 9vw, 3.5rem);
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 1;
  margin: 0 0 12px;
}

.intro-description {
  font-size: 0.9375rem;
  color: var(--gray-70);
  line-height: 1.6;
  max-width: 380px;
  margin: 0 auto 20px;
}

.intro-byline {
  font-size: 0.875rem;
  color: var(--gray-60);
  margin: 0;
}

/* Theme selection */
#theme-select {
  padding: 8px 0 24px;
}

.theme-select-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gray-40);
  margin: 0 0 20px;
}

.theme-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  max-width: 540px;
  margin: 0 auto;
}

.theme-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 28px 24px;
  background: #fff;
  border: 1px solid var(--gray-20);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
  font-family: 'Inter', sans-serif;
  font-size: inherit;
  text-transform: none;
  letter-spacing: normal;
  color: var(--fg);
}

.theme-card:hover {
  border-color: var(--fg);
  background: var(--surface);
}

.theme-card-emoji {
  font-size: 2.25rem;
  line-height: 1;
}

.theme-card-name {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--fg);
}

.theme-card-desc {
  font-size: 0.8125rem;
  color: var(--gray-60);
  font-weight: 400;
  line-height: 1.4;
}

@media (max-width: 520px) {
  .theme-cards { grid-template-columns: 1fr; max-width: 100%; }
}

/* Daily complete screen */
#daily-complete {
  text-align: center;
  padding: 16px 0;
}

#daily-complete h2 {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.05em;
  margin: 0 0 8px;
}

.daily-complete-sub {
  font-size: 0.9375rem;
  color: var(--gray-60);
  margin: 0 0 28px;
}

.daily-summary {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 28px;
  text-align: left;
}

.daily-theme-block {
  border: 1px solid var(--gray-20);
  padding: 14px 16px;
  background: #fff;
}

.daily-theme-title {
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.daily-time {
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--gray-40);
}

.daily-rows {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.daily-row {
  font-family: 'DM Mono', monospace;
  font-size: 0.8125rem;
  color: var(--gray-70);
}

.daily-return {
  font-size: 0.875rem;
  color: var(--gray-40);
  margin: 20px 0 0;
  font-style: italic;
}

/* Theme card done state */
.theme-card-done {
  opacity: 0.5;
  cursor: not-allowed;
}

.theme-done-badge {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--success);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-left: 6px;
}

/* Final screen */
#final {
  text-align: center;
  padding: 16px 0;
}

#final h2 {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.05em;
  margin: 0 0 16px;
}

#final.perfect {
  animation: perfect-arrive 0.5s ease-out;
}

#final.perfect h2 {
  color: #16a34a;
}

@keyframes perfect-arrive {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.final-message {
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.6;
  color: var(--gray-70);
  max-width: 480px;
  margin: 0 auto 24px;
  border-left: 3px solid #16a34a;
  padding-left: 16px;
  text-align: left;
}

#finalScores {
  font-family: 'DM Mono', monospace;
  font-size: 0.875rem;
  color: var(--gray-60);
  margin-bottom: 24px;
  line-height: 1.8;
}

/* Color key */
.color-key {
  display: flex;
  gap: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.key-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-40);
}

.key-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.swatch-correct { background: #16a34a; }
.swatch-present { background: #d97706; }
.swatch-wrong   { background: #dc2626; }

.hidden { display: none; }

/* Divider above working area */
.word-count {
  font-weight: 400;
  color: var(--gray-40);
  text-transform: none;
  letter-spacing: 0;
}

.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-40);
  margin-bottom: 6px;
}
