:root {
  --ink: #181611;
  --muted: #6d665b;
  --paper: #f6f3ed;
  --panel: #fffdf8;
  --line: #d8d0c2;
  --red: #b62036;
  --green: #176a52;
  --blue: #2e5f8f;
  --gold: #b88525;
  --shadow: 0 18px 55px rgba(28, 23, 14, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(24, 22, 17, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(24, 22, 17, 0.04) 1px, transparent 1px),
    var(--paper);
  background-size: 34px 34px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: end;
  padding: 28px clamp(18px, 4vw, 56px) 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(14px);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 3.5vw, 3.2rem);
  line-height: 1;
  max-width: 820px;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.45rem, 2.5vw, 2.25rem);
}

h3 {
  margin-bottom: 10px;
}

.kicker {
  margin-bottom: 7px;
  color: var(--green);
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  font-size: 0.78rem;
}

.nav-tabs,
.controls-row,
.timeline,
.tag-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.tab,
.ghost,
.primary,
.icon-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  min-height: 40px;
  padding: 9px 13px;
  font-weight: 750;
}

.tab.active,
.primary {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.ghost:hover,
.tab:hover,
.icon-button:hover {
  border-color: var(--green);
}

main {
  padding: 24px clamp(14px, 3vw, 42px) 48px;
}

.panel {
  display: none;
  max-width: 1440px;
  margin: 0 auto;
}

.active-section {
  display: block;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin-bottom: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  min-width: 0;
}

textarea {
  resize: vertical;
}

.visual-grid,
.analyzer-grid,
.writer-grid {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 310px;
  gap: 16px;
}

.writer-grid {
  grid-template-columns: minmax(280px, 0.9fr) minmax(280px, 1.1fr);
}

.steps-list,
.method-card,
.video-box,
.clue-grid,
.guess-panel,
.routine-form,
.routine-preview {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.step-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  padding: 10px;
  color: var(--muted);
}

.step-item strong {
  display: block;
  color: var(--ink);
}

.step-item.active {
  border-color: rgba(23, 106, 82, 0.45);
  background: rgba(23, 106, 82, 0.08);
}

.table-zone {
  min-height: 610px;
}

.closeup-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.closeup {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px;
  min-height: 78px;
}

.closeup b {
  display: block;
  margin-bottom: 4px;
}

.card-table {
  position: relative;
  min-height: 455px;
  overflow: hidden;
  border: 1px solid #0d4c3a;
  border-radius: 8px;
  background:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.12), transparent 24%),
    linear-gradient(135deg, #105742, #0f4436 58%, #123528);
  box-shadow: inset 0 0 0 8px rgba(255, 255, 255, 0.05), var(--shadow);
}

.table-label {
  position: absolute;
  left: 18px;
  top: 18px;
  color: rgba(255, 255, 255, 0.88);
  max-width: 460px;
  line-height: 1.45;
}

.card {
  position: absolute;
  width: 74px;
  height: 104px;
  border-radius: 7px;
  border: 1px solid rgba(24, 22, 17, 0.22);
  background: #fffdf8;
  color: var(--ink);
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  font-weight: 900;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.2);
  transition: transform 320ms ease, opacity 220ms ease;
}

.card.red {
  color: var(--red);
}

.card.back {
  color: transparent;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.14) 25%, transparent 25% 50%, rgba(255, 255, 255, 0.14) 50% 75%, transparent 75%),
    var(--blue);
  background-size: 18px 18px;
}

.card.marked {
  outline: 4px solid rgba(184, 133, 37, 0.82);
}

.card.ghosted {
  opacity: 0.22;
}

.note {
  position: absolute;
  width: 128px;
  min-height: 86px;
  border-radius: 6px;
  background: #fff9d9;
  border: 1px solid rgba(184, 133, 37, 0.55);
  padding: 12px;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.18);
  transform: rotate(-3deg);
}

.timeline {
  margin-top: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.timeline input {
  flex: 1;
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 1.5rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 9px;
  color: var(--muted);
  background: #fff;
  font-size: 0.83rem;
  font-weight: 800;
}

.analyzer-grid {
  grid-template-columns: minmax(300px, 1.1fr) minmax(300px, 0.9fr) minmax(280px, 0.8fr);
}

.upload-target {
  display: grid;
  place-items: center;
  border: 1px dashed var(--green);
  background: rgba(23, 106, 82, 0.08);
  border-radius: 8px;
  min-height: 58px;
  margin-bottom: 12px;
}

.upload-target input {
  display: none;
}

video,
canvas {
  width: 100%;
  border-radius: 8px;
  background: #161616;
  display: block;
  margin-bottom: 10px;
}

canvas {
  min-height: 180px;
}

.stat-line {
  color: var(--muted);
  line-height: 1.45;
}

.clue-grid {
  display: grid;
  gap: 10px;
  align-content: start;
}

.clue-grid label {
  grid-template-columns: 20px 1fr;
  align-items: start;
  color: var(--ink);
  font-weight: 650;
}

.clue-grid input {
  margin-top: 3px;
}

.meter {
  height: 13px;
  border-radius: 999px;
  background: #e8e0d3;
  overflow: hidden;
  margin-bottom: 16px;
}

#guessMeter {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--green));
}

.ranked {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.rank-row {
  display: grid;
  grid-template-columns: 1fr 54px;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.routine-form {
  display: grid;
  gap: 12px;
}

.routine-preview dl {
  display: grid;
  gap: 12px;
}

.routine-preview dt {
  font-weight: 900;
  color: var(--green);
}

.routine-preview dd {
  margin: 2px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

#exportBox {
  width: 100%;
  margin-top: 14px;
}

.search {
  min-width: min(420px, 100%);
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.library-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.library-card p {
  color: var(--muted);
  line-height: 1.48;
}

.mini-cards {
  height: 82px;
  position: relative;
  margin-bottom: 12px;
}

.mini-card {
  position: absolute;
  width: 48px;
  height: 68px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--line);
  transform: rotate(var(--r)) translateX(var(--x));
  display: grid;
  place-items: center;
  font-weight: 900;
  color: var(--c);
}

@media (max-width: 1080px) {
  .topbar,
  .section-head,
  .visual-grid,
  .analyzer-grid,
  .writer-grid {
    grid-template-columns: 1fr;
  }

  .section-head {
    align-items: start;
  }

  .table-zone {
    min-height: auto;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding-inline: 14px;
  }

  main {
    padding-inline: 10px;
  }

  .nav-tabs {
    width: 100%;
  }

  .tab {
    flex: 1 1 140px;
  }

  .closeup-strip {
    grid-template-columns: 1fr;
  }

  .card-table {
    min-height: 390px;
  }

  .card {
    width: 56px;
    height: 80px;
    font-size: 0.88rem;
  }
}
