:root {
  --paper: #f6f3e8;
  --ink: #161515;
  --accent: #ff6a3d;
  --accent-dark: #c94b25;
  --line: #d8d2c1;
  --muted: #5a5348;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  font-family: "Nunito", "Avenir Next", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 20%, #fff7df, #f1e8cf 45%, #e8dcc0 100%);
}

body.cgs-start-page {
  background: transparent;
}

.shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

.global-debug-banner {
  position: sticky;
  top: 0;
  z-index: 1000;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 1rem;
  background: #2d2a00;
  color: #fff5a8;
  border-bottom: 1px solid #5f5600;
  font-size: 0.86rem;
}

.global-test-mode-banner {
  position: sticky;
  top: 0;
  z-index: 1100;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 1rem;
  background: #601414;
  color: #ffe4c4;
  border-bottom: 1px solid #8f2a2a;
  font-size: 0.88rem;
}

.global-test-mode-banner strong {
  letter-spacing: 0.05em;
}

.global-test-mode-banner + .global-debug-banner {
  top: 2rem;
}

.global-debug-banner strong {
  letter-spacing: 0.05em;
}

.flash-wrap {
  margin-bottom: 1rem;
}

.flash {
  border: 1px solid var(--line);
  background: #fff;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
}

.card {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 1rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  padding: 1rem;
}

.auth-card {
  max-width: 900px;
  margin: 1rem auto;
}

.cgs-start-page .shell {
  position: relative;
  min-height: 100vh;
}

.cgs-start-page .start-page-mosaic {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  overflow: hidden;
  opacity: 0.06;
  filter: saturate(0.95) contrast(1.02);
  pointer-events: none;
}

.cgs-start-page .auth-card {
  position: relative;
  z-index: 1;
}

.cgs-start-page .start-page-attribution {
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 2;
  margin: 0;
  color: rgba(22, 21, 21, 0.72);
  font-size: 0.75rem;
  line-height: 1.25;
  letter-spacing: 0.02em;
  white-space: nowrap;
  pointer-events: none;
  text-wrap: balance;
}

.cgs-start-page .start-page-tile {
  position: absolute;
  display: block;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.start-hero {
  position: relative;
  overflow: hidden;
  min-height: 32rem;
  isolation: isolate;
}

.start-hero-content {
  position: relative;
  z-index: 1;
}

.study-title {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.study-title-icon {
  width: 3rem;
  height: 3rem;
  flex: 0 0 auto;
  background-color: var(--ink);
  -webkit-mask-image: url('/static/creative_game_study/favicon.png');
  mask-image: url('/static/creative_game_study/favicon.png');
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
}

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

.panel {
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 1rem;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.app-card {
  min-height: calc(100vh - 2.5rem);
}

.cgs-create-page .shell {
  max-width: none;
  margin: 0;
  padding: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cgs-app {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cgs-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--line);
  padding: 0.5rem 1rem;
  background: #111;
}

.progress-status {
  color: #8be08b;
  font-weight: 700;
  font-size: 0.92rem;
  text-align: center;
  flex: 1;
}

.progress-status.unsaved {
  color: #ff6363;
}

.progress-status-link {
  color: inherit;
  text-decoration: underline;
}

.progress-status-link:hover {
  opacity: 0.85;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
}

.tab {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}

.tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-dark);
}

.cgs-topbar .tab {
  background: #1b1b1b;
  color: #f5f5f5;
  border-color: #3a3a3a;
}

.cgs-topbar .tab:hover {
  background: #262626;
  border-color: #555;
}

.cgs-topbar .tab.active {
  background: #000;
  color: #fff;
  border-color: #7a7a7a;
}

.cgs-topbar .header-actions .secondary,
.cgs-topbar .header-actions button.secondary {
  background: #1b1b1b;
  color: #f5f5f5;
  border-color: #3a3a3a;
}

.cgs-topbar .header-actions .secondary:hover,
.cgs-topbar .header-actions button.secondary:hover {
  background: #262626;
  border-color: #555;
}

.tab-panel {
  display: none;
  margin-top: 0;
}

.tab-panel.active {
  display: block;
}

#create-tab.tab-panel.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#play-tab.tab-panel.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.creation-flow {
  --survey-side-gutter: clamp(0.75rem, 2.5vw, 1.5rem);
  --survey-top-gutter: 0.75rem;
  --survey-bottom-gutter: 0.75rem;
  padding: var(--survey-top-gutter) var(--survey-side-gutter) var(--survey-bottom-gutter);
  display: block;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: visible;
}

.creation-flow.hidden {
  display: none;
}

.survey-panel {
  width: max-content;
  min-width: 100%;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 0.75rem;
}

.survey-panel.hidden {
  display: none;
}

.survey-panel h2 {
  margin: 0 0 0.4rem;
}

.survey-open-response-notice {
  width: max-content;
  min-width: 100%;
  margin-bottom: 0.9rem;
  box-sizing: border-box;
}

.survey-open-response-notice p {
  margin: 0;
}

.survey-fields {
  display: grid;
  gap: 4ch;
  width: max-content;
  min-width: 100%;
}

#pre-survey-form.panel,
#post-survey-form.panel,
#play-survey-form.panel {
  width: max-content;
  min-width: 100%;
  box-sizing: border-box;
}

#play-survey-flow {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: visible;
}

#play-survey-panel {
  width: max-content;
  min-width: 100%;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 0.75rem;
}

#play-survey-form.panel {
  width: max-content;
  min-width: 100%;
  box-sizing: border-box;
  overflow: visible;
  display: flex;
  margin-bottom: 0;
}

#play-survey-fields.survey-fields,
#play-survey-form.panel .survey-fields {
  width: max-content;
  min-width: 100%;
}

.survey-row {
  display: grid;
  gap: 0.35rem;
}

.survey-section {
  display: grid;
  gap: 0.35rem;
}

.story-prompt-options {
  display: grid;
  gap: 0.55rem;
}

.story-prompt-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.6rem;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  padding: 0.55rem 0.6rem;
  background: #fff;
}

.revisit-prompt-section {
  border-top: 1px dashed var(--line);
  padding-top: 0.6rem;
  margin-top: 0.2rem;
  display: grid;
  gap: 0.55rem;
}

.revisit-prompt-section.no-separator {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.revisit-prompt-section.hidden {
  display: none;
}

.revisit-prompt-label {
  margin: 0 0 1rem;
}

#revisit-see-more-btn.hidden {
  display: none;
}

#revisit-see-more-btn {
  text-align: left;
  padding: 0.42rem 0.72rem;
  line-height: 1.15;
}

.prompt-debug-panel {
  margin-top: 0.6rem;
}

.prompt-debug-panel h3,
.prompt-debug-panel h4 {
  margin: 0 0 0.35rem;
}

.prompt-debug-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 0.6rem;
}

.prompt-debug-seen-last-round {
  margin-top: 0.75rem;
}

.prompt-debug-list {
  margin: 0;
  padding-left: 1rem;
  display: grid;
  gap: 0.25rem;
}

.survey-prompt {
  font-weight: 700;
}

.survey-text-row {
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
}

.likert-table {
  display: inline-table;
  width: auto;
  max-width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
  background: #fff;
  margin: 0;
  table-layout: fixed;
}

.likert-table th,
.likert-table td {
  border: 1px solid var(--line);
  padding: 0.5rem 0.45rem;
  vertical-align: middle;
}

.likert-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  font-weight: 700;
  text-align: center;
  background: #fff;
}

.creation-flow.is-scrolled .likert-table thead th,
#play-tab.is-scrolled .likert-table thead th {
  top: calc(-1 * var(--survey-top-gutter));
  border-top-color: transparent;
  border-bottom-color: transparent;
  box-shadow: inset 0 1px 0 var(--line), inset 0 -1px 0 var(--line);
}

.likert-question-header,
.likert-question-cell {
  text-align: left;
  white-space: nowrap;
}

.likert-table.likert-questions-wrap .likert-question-cell {
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: manual;
}

.likert-option-header,
.likert-option-cell {
  text-align: center;
}

.likert-table td.likert-option-cell {
  padding: 0;
}

.likert-option-header {
  white-space: nowrap;
}

.likert-table.likert-options-wrap .likert-option-header {
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: manual;
}

.likert-table .likert-option {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 2.25rem;
  padding: 0.5rem 0.45rem;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}

.likert-table .likert-option input {
  justify-self: center;
  align-self: center;
  margin: 0;
}

.likert-table .likert-option::after {
  content: none;
}

.likert-table .likert-option:has(input:checked) {
  background: rgba(232, 232, 255, 0.9);
}

.survey-row textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  padding: 0.5rem;
  resize: vertical;
  font: inherit;
}

.editor-wrap {
  margin-top: 0;
  width: 100%;
  flex: 1;
  min-height: 0;
  min-width: 0;
  line-height: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: transparent;
}

#create-tab .editor-wrap {
  flex: 1 1 0;
  min-height: 0;
  height: 100%;
}

.play-wrap {
  flex: 1;
  min-height: 0;
  height: auto;
}

#play-tab #play-runtime .play-wrap {
  flex: 0 0 auto;
  align-self: center;
  width: min(100%, 512px);
  max-width: 100%;
  min-width: 0;
  aspect-ratio: 1 / 1;
  height: auto;
}

#play-tab #play-runtime #play-game-frame {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}

.play-actions {
  display: flex;
  justify-content: flex-end;
}

.play-empty-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.6rem;
}

#play-empty-status {
  margin: 0.35rem 0 0;
}

#play-tab #play-empty-state {
  width: min(100%, 640px);
  margin: 2rem auto 0;
}

.play-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(100%, 512px);
  max-width: 100%;
  align-self: center;
}

.play-instructions {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
}

#play-runtime {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
  gap: 0.5rem;
  margin-top: 2rem;
}



.editor-wrap iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.editor-wrap iframe.editor-loading {
  visibility: hidden;
}

.editor-wrap:has(iframe.editor-loading) {
  background: #ccccff;
}

.game-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}

.game-item {
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.85rem;
  background: #fff;
}

.publish-status {
  margin: 0.35rem 0 0;
}

.publish-status.hidden {
  display: none;
}

.modal-shell {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 30;
}

.modal-shell.hidden {
  display: none;
}

.modal-card {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: #fff;
  padding: 1rem;
  box-shadow: 0 16px 35px rgba(0, 0, 0, 0.22);
}

.modal-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.4rem;
}

.form-error {
  margin: 0;
  color: #b42c2c;
  font-weight: 700;
}

.form-error.hidden {
  display: none;
}

button,
.button-link {
  border: 1px solid var(--accent-dark);
  background: var(--accent);
  color: #fff;
  border-radius: 0.55rem;
  padding: 0.55rem 0.8rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

input[type="email"] {
  width: 100%;
  margin-top: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.55rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.consent-panel p:first-of-type {
  margin-top: 0;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal {
  background: white;
  border-radius: 1rem;
  padding: 2rem;
  max-width: 450px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  color: var(--muted);
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--ink);
}

.modal h2 {
  margin: 0 0 1rem;
  font-size: 1.3rem;
}

.modal p {
  margin: 0 0 1.5rem;
  line-height: 1.5;
}

.modal-button {
  width: 100%;
  text-align: center;
}

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

.eyebrow {
  margin: 0 0 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  color: var(--accent-dark);
  font-weight: 800;
}

.admin-hero {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
  border-radius: 1rem;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 245, 229, 0.92));
  border: 1px solid var(--line);
}

.admin-hero h2 {
  margin: 0 0 0.4rem;
}

.admin-hero-note {
  min-width: 220px;
  padding: 0.9rem 1rem;
  border-radius: 0.9rem;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.admin-summary-grid {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 1rem;
}

.stat-card {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  border-radius: 0.9rem;
  padding: 0.95rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.accent-card {
  background: linear-gradient(180deg, rgba(255, 106, 61, 0.14), rgba(255, 255, 255, 0.9));
  border-color: rgba(201, 75, 37, 0.35);
}

.stat-label {
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 800;
}

.stat-value {
  font-size: 2rem;
  line-height: 1;
}

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

.bar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 160px;
}

.bar-track {
  flex: 1;
  height: 0.55rem;
  border-radius: 999px;
  background: #efe8d7;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-dark));
}

.bar-label {
  white-space: nowrap;
  font-size: 0.84rem;
  color: var(--muted);
  min-width: 3.5rem;
  text-align: right;
}

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

.admin-section {
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: #fff;
  padding: 0.85rem;
}

.admin-section-wide {
  grid-column: 1 / -1;
}

.admin-section h2 {
  margin-top: 0;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 0.45rem 0.35rem;
  vertical-align: top;
}

.admin-table th {
  color: var(--muted);
  font-weight: 700;
}

.admin-table tr:last-child td {
  border-bottom: none;
}

.participant-matrix-stack {
  display: grid;
  gap: 0.9rem;
}

.participant-matrix-card {
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: #fcfbf7;
  padding: 0.8rem;
}

.participant-matrix-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.5rem;
}

.participant-matrix-header h3 {
  margin: 0;
}

.participant-matrix-header p {
  margin: 0;
}

.participant-matrix-wrap {
  overflow: auto;
}

.participant-matrix-table {
  min-width: 680px;
}

.participant-matrix-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.matrix-variant-header {
  white-space: nowrap;
  font-size: 0.78rem;
}

.matrix-cell {
  text-align: center;
}

.matrix-checkbox {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  border: 1px solid #9f9681;
  border-radius: 0.2rem;
  font-size: 0.72rem;
  line-height: 1;
  font-weight: 800;
  color: transparent;
  background: #fff;
}

.matrix-checkbox.complete {
  color: #1d6735;
  background: #e8f6ec;
  border-color: #63a97d;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.inline-form {
  display: inline;
}

@media (max-width: 780px) {
  .cgs-create-page .shell {
    height: 100dvh;
    min-height: 100vh;
  }

  .cgs-app {
    height: 100%;
    min-height: 0;
  }

  .cgs-topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    flex-wrap: wrap;
  }

}
