:root {
  --ink: #191714;
  --paper: #f5f1e8;
  --paper-deep: #e8e1d3;
  --card: #fffdf8;
  --muted: #716b62;
  --line: rgba(25, 23, 20, 0.16);
  --accent: #ff5c35;
  --accent-dark: #d83d19;
  --shadow: 0 18px 55px rgba(37, 30, 21, 0.12);
  --radius: 22px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 85% 10%, rgba(255, 92, 53, 0.12), transparent 30rem),
    radial-gradient(circle at 10% 60%, rgba(103, 151, 190, 0.12), transparent 34rem),
    var(--paper);
  font-family: "DM Sans", system-ui, sans-serif;
}

button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.grain {
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0.24;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.08'/%3E%3C/svg%3E");
}

.site-header {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  font-family: "Fraunces", serif;
  font-size: 1.45rem;
  font-weight: 700;
}

.brand-mark {
  width: 31px;
  height: 31px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  transform: rotate(5deg);
}

.brand-mark i { border-radius: 4px; }
.brand-mark i:nth-child(1) { background: #f3ca52; }
.brand-mark i:nth-child(2) { background: #78b77b; }
.brand-mark i:nth-child(3) { background: #6b9fd2; }
.brand-mark i:nth-child(4) { background: #a77abb; }

.main-nav { display: flex; gap: 8px; }
.main-nav a {
  padding: 9px 14px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}
.main-nav a.active, .main-nav a:hover { color: var(--ink); background: rgba(255, 255, 255, 0.55); }

main {
  width: min(1180px, calc(100% - 40px));
  min-height: calc(100vh - 180px);
  margin: 0 auto;
}

.home {
  min-height: 70vh;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: clamp(40px, 8vw, 110px);
  align-items: center;
  padding: 40px 0 80px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 18px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.eyebrow::before { content: ""; width: 24px; height: 2px; background: currentColor; }

h1, h2, h3 { font-family: "Fraunces", serif; }
h1 {
  max-width: 750px;
  margin: 0;
  font-size: clamp(3.2rem, 7vw, 6.8rem);
  line-height: 0.95;
  letter-spacing: -0.055em;
}

.lede {
  max-width: 590px;
  margin: 26px 0 32px;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.18rem);
  line-height: 1.65;
}

.play-form {
  max-width: 560px;
  display: flex;
  padding: 7px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.play-form input {
  min-width: 0;
  flex: 1;
  padding: 13px 14px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 13px 20px;
  cursor: pointer;
  color: white;
  background: var(--ink);
  font-weight: 700;
  transition: transform 0.18s ease, background 0.18s ease, opacity 0.18s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; transform: none; }
.btn-accent { background: var(--accent); }
.btn-accent:hover { background: var(--accent-dark); }
.btn-ghost { color: var(--ink); background: transparent; border: 1px solid var(--line); }
.btn-danger { color: #a22913; background: #ffe6df; }
.btn-small { padding: 9px 13px; font-size: 0.86rem; }

.demo-link {
  display: inline-block;
  color: var(--muted);
  font-size: 0.9rem;
  text-underline-offset: 4px;
}

.home-actions {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-top: 18px;
}

.hero-art {
  position: relative;
  min-height: 480px;
}
.floating-card {
  position: absolute;
  width: clamp(150px, 18vw, 225px);
  aspect-ratio: 1.35;
  display: grid;
  place-items: center;
  border: 1px solid rgba(25, 23, 20, 0.08);
  border-radius: 22px;
  box-shadow: 0 25px 60px rgba(45, 34, 21, 0.16);
  font-family: "Fraunces", serif;
  font-size: clamp(1.1rem, 2vw, 1.5rem);
  font-weight: 700;
}
.floating-card:nth-child(1) { top: 0; left: 5%; background: #f3ca52; transform: rotate(-8deg); }
.floating-card:nth-child(2) { top: 18%; right: 0; background: #78b77b; transform: rotate(7deg); }
.floating-card:nth-child(3) { bottom: 18%; left: 0; background: #6b9fd2; transform: rotate(5deg); }
.floating-card:nth-child(4) { right: 8%; bottom: 0; color: white; background: #a77abb; transform: rotate(-6deg); }
.orbit {
  position: absolute;
  inset: 11% 10%;
  border: 1px dashed rgba(25, 23, 20, 0.18);
  border-radius: 50%;
  transform: rotate(-20deg);
}

.page-head {
  max-width: 760px;
  margin: 55px auto 32px;
  text-align: center;
}
.page-head h1 { font-size: clamp(2.5rem, 6vw, 4.6rem); }
.page-head p { color: var(--muted); line-height: 1.6; }

.game-shell { max-width: 850px; margin: 0 auto 80px; }
.game-meta { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 22px; }
.game-meta h2 { margin: 0 0 5px; font-size: clamp(1.8rem, 4vw, 2.7rem); }
.game-meta p { margin: 0; color: var(--muted); }
.mistakes { white-space: nowrap; color: var(--muted); font-size: 0.9rem; }
.mistake-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-left: 5px;
  border-radius: 50%;
  background: var(--ink);
  vertical-align: -1px;
}
.mistake-dot.used { background: var(--paper-deep); }

.solved-list { display: grid; gap: 8px; margin-bottom: 8px; }
.solved-group {
  padding: 19px;
  border-radius: 14px;
  text-align: center;
  animation: reveal 0.35s ease both;
}
.solved-group h3 { margin: 0 0 6px; font-family: "DM Sans", sans-serif; font-size: 0.94rem; text-transform: uppercase; letter-spacing: 0.06em; }
.solved-group p { margin: 0; font-size: 0.9rem; }

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.word-card {
  min-width: 0;
  min-height: 98px;
  padding: 9px;
  border: 1px solid rgba(25, 23, 20, 0.06);
  border-radius: 14px;
  color: var(--ink);
  background: rgba(255, 253, 248, 0.9);
  box-shadow: 0 7px 22px rgba(45, 34, 21, 0.05);
  cursor: pointer;
  font-size: clamp(0.72rem, 1.7vw, 0.94rem);
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
  text-transform: uppercase;
  transition: transform 0.16s ease, background 0.16s ease, color 0.16s ease;
}
.word-card:hover { transform: translateY(-2px); }
.word-card.selected { color: white; background: var(--ink); transform: scale(0.97); }
.word-card.image-card { padding: 5px; overflow: hidden; }
.word-card.image-card.selected { box-shadow: inset 0 0 0 5px var(--ink); background: var(--ink); }
.card-image {
  width: 100%;
  height: 100%;
  max-height: 120px;
  display: block;
  object-fit: cover;
  border-radius: 9px;
}
.card-image.compact {
  width: 46px;
  height: 34px;
  margin: 0 auto;
  border-radius: 6px;
}
.board.shake { animation: shake 0.35s ease; }

.game-actions { display: flex; justify-content: center; gap: 10px; margin: 22px 0; }
.game-message { min-height: 25px; margin: 0; text-align: center; color: var(--accent-dark); font-weight: 700; }
.game-message.info { color: #386b8d; }
.game-message.success { color: #397347; }

.solved-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
  max-width: 600px;
  margin: 0 auto;
  font-size: 0.84rem;
  font-weight: 600;
  text-transform: uppercase;
}

.result-card {
  max-width: 440px;
  margin: 22px auto;
  padding: 28px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  text-align: center;
}
.result-card h3 { margin-top: 0; font-size: 1.8rem; }
.result-grid { margin: 20px auto; font-size: 1.42rem; line-height: 1.35; letter-spacing: 0.08em; white-space: pre-line; }

.studio-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  gap: 24px;
  align-items: start;
  margin: 20px 0 80px;
}
.panel {
  padding: clamp(20px, 4vw, 34px);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.panel h2 { margin-top: 0; }
.field { display: grid; gap: 7px; margin-bottom: 17px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field label, .group-editor > label { font-size: 0.82rem; font-weight: 700; }
.field small { color: var(--muted); }
.input {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 92, 53, 0.12); }

.image-note {
  padding: 12px 14px;
  border: 1px solid rgba(56, 107, 141, 0.18);
  border-radius: 10px;
  color: #386b8d;
  background: rgba(107, 159, 210, 0.1);
  font-size: 0.82rem;
  line-height: 1.5;
}

.group-editors { display: grid; gap: 12px; margin: 22px 0; }
.group-editor {
  padding: 15px;
  border-left: 6px solid var(--group-color);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.54);
}
.group-editor-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 11px; }
.group-editor-head span { color: var(--muted); font-size: 0.78rem; }
.word-inputs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 8px; }
.word-inputs .input { padding: 10px; text-align: center; font-size: 0.82rem; font-weight: 700; text-transform: uppercase; }
.card-editors { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 9px; }
.card-editor { min-width: 0; display: grid; gap: 7px; align-content: start; }
.card-editor .input { min-width: 0; padding: 9px; font-size: 0.78rem; }
.card-editor .card-text { min-height: 44px; text-align: center; font-weight: 700; text-transform: uppercase; }
.image-picker {
  position: relative;
  min-height: 92px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px dashed var(--line);
  border-radius: 9px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  font-size: 0.75rem;
  text-align: center;
}
.image-picker:hover { border-color: var(--accent); }
.image-picker.processing { opacity: 0.5; pointer-events: none; }
.image-picker.processing::after { content: "Resizing…"; position: absolute; inset: 0; display: grid; place-items: center; color: white; background: rgba(25,23,20,.7); }
.image-picker img { width: 100%; height: 92px; object-fit: cover; }
.image-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.key-box { padding: 15px; border-radius: 12px; background: #f1eadc; }
.key-box p { margin-top: 0; color: var(--muted); font-size: 0.88rem; line-height: 1.5; }
.key-row { display: flex; gap: 7px; }

.level-list { display: grid; gap: 10px; margin-top: 22px; }
.level-item { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.5); }
.level-item h3 { margin: 0 0 4px; font-family: "DM Sans", sans-serif; font-size: 0.97rem; }
.level-item p { margin: 0 0 12px; color: var(--muted); font-size: 0.8rem; }
.item-actions { display: flex; gap: 7px; }
.empty { color: var(--muted); font-size: 0.9rem; line-height: 1.55; }

.library-section {
  padding: 60px 0 90px;
  border-top: 1px solid var(--line);
}
.library-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: 28px;
}
.library-head h2 { margin: 0; font-size: clamp(2rem, 5vw, 3.6rem); }
.library-head > p { max-width: 330px; margin: 0; color: var(--muted); line-height: 1.6; }
.creator-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.creator-card {
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 17px;
  background: rgba(255, 253, 248, 0.74);
  box-shadow: 0 10px 32px rgba(45, 34, 21, 0.07);
}
.creator-card h3 { margin: 0 0 4px; font-size: 1.45rem; }
.creator-card > p { margin: 0 0 17px; color: var(--muted); font-size: 0.8rem; }
.creator-levels { display: grid; gap: 7px; }
.level-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 9px;
  background: rgba(232, 225, 211, 0.58);
  text-decoration: none;
  font-size: 0.86rem;
}
.level-link b { color: var(--accent-dark); font-size: 0.75rem; white-space: nowrap; }
.level-link:hover { background: var(--paper-deep); }
.played-badge {
  display: inline-block;
  margin-left: 5px;
  padding: 2px 6px;
  border-radius: 999px;
  color: #397347;
  background: rgba(120, 183, 123, 0.16);
  font-size: 0.62rem;
  font-style: normal;
  font-weight: 700;
  text-transform: uppercase;
  vertical-align: 1px;
}

.history-section {
  padding: 70px 0 90px;
  border-top: 1px solid var(--line);
}
.history-list { display: grid; gap: 10px; }
.history-item {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto auto;
  gap: 18px;
  align-items: center;
  padding: 16px 18px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 14px;
  background: rgba(255, 253, 248, 0.72);
}
.history-result {
  min-width: 54px;
  padding: 7px 8px;
  border-radius: 8px;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}
.history-result.won { color: #397347; background: rgba(120, 183, 123, 0.18); }
.history-result.lost { color: #a22913; background: #ffe6df; }
.history-copy h3 { margin: 0 0 3px; font-family: "DM Sans", sans-serif; font-size: 0.94rem; }
.history-copy p { margin: 0; color: var(--muted); font-size: 0.76rem; }
.history-grid {
  font-size: 0.72rem;
  line-height: 1.05;
  letter-spacing: -0.08em;
  white-space: pre-line;
}
.history-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  color: var(--muted);
  font-size: 0.75rem;
}

.error-state { max-width: 600px; margin: 100px auto; text-align: center; }
.error-state h1 { font-size: 3rem; }
.error-state p { color: var(--muted); }

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 24px;
  padding: 11px 16px;
  border-radius: 10px;
  color: white;
  background: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: 0.22s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

footer { padding: 24px; color: var(--muted); text-align: center; font-size: 0.8rem; }

@keyframes reveal {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
}
@keyframes shake {
  20%, 60% { transform: translateX(-7px); }
  40%, 80% { transform: translateX(7px); }
}

@media (max-width: 850px) {
  .home { grid-template-columns: 1fr; padding-top: 65px; }
  .hero-art { display: none; }
  .studio-layout { grid-template-columns: 1fr; }
  .studio-side { order: -1; }
  .creator-grid { grid-template-columns: 1fr 1fr; }
  .card-editors { grid-template-columns: 1fr 1fr; }
  .history-item { grid-template-columns: auto 1fr auto; }
  .history-grid { display: none; }
}

@media (max-width: 610px) {
  .site-header, main { width: min(100% - 24px, 1180px); }
  .site-header { padding-top: 16px; }
  .brand { font-size: 1.2rem; }
  .main-nav a { padding: 8px 10px; }
  .home { min-height: 76vh; padding-top: 35px; }
  h1 { font-size: clamp(3rem, 16vw, 4.6rem); }
  .play-form { flex-direction: column; gap: 4px; }
  .board { gap: 6px; }
  .word-card { min-height: 76px; border-radius: 10px; }
  .game-meta { align-items: start; flex-direction: column; }
  .word-inputs { grid-template-columns: 1fr 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .panel { padding: 18px; }
  .creator-grid { grid-template-columns: 1fr; }
  .library-head { align-items: start; flex-direction: column; }
  .home-actions { align-items: flex-start; flex-direction: column; }
  .history-item { grid-template-columns: auto 1fr; gap: 11px; }
  .history-actions { grid-column: 1 / -1; justify-content: space-between; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
