:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #dbe2ea;
  --border-strong: #c9d3dd;
  --text: #0f172a;
  --muted: #5b6778;
  --accent: #2563eb;
  --accent-weak: #dbeafe;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 6px 18px rgba(15, 23, 42, 0.06);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

@tailwind base;
@tailwind components;
@tailwind utilities;

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  overflow: auto;
}

main {
  min-height: 100dvh;
  overflow: visible;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
textarea {
  font: inherit;
}

button,
.page-actions a,
.library-add-button,
.play-card__action {
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  padding: 0.5rem 0.8rem;
  min-height: 2.25rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease, background 120ms ease;
}

.page-action-link {
  padding: 0.32rem 0.6rem;
  min-height: 1.8rem;
  font-size: 0.88rem;
  background: transparent;
  box-shadow: none;
}

.page-action-link:hover {
  background: rgba(37, 99, 235, 0.06);
  box-shadow: none;
}

.icon-button {
  inline-size: 2.35rem;
  min-inline-size: 2.35rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
}

button:hover,
.page-actions a:hover,
.library-add-button:hover,
.play-card__action:hover {
  transform: translateY(-1px);
  border-color: #b7c2ce;
  box-shadow: var(--shadow-soft);
  text-decoration: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.18);
  outline-offset: 2px;
  border-color: var(--accent);
}

input,
textarea {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 0.72rem 0.85rem;
  box-sizing: border-box;
}

textarea {
  resize: vertical;
}

.player-page,
.editor-page {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1rem;
  box-sizing: border-box;
  overflow: hidden;
}

.page-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.25rem 0.1rem;
}

.page-title-group {
  display: grid;
  gap: 0.25rem;
}

.page-brand,
.library-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.site-logo {
  inline-size: 2rem;
  block-size: 2rem;
  object-fit: contain;
  flex: none;
}

.page-title-group h1,
.page-title-group h2,
.page-title-group p {
  margin: 0;
}

.page-title-group h1 {
  font-size: 1.35rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.page-title-group p {
  color: var(--muted);
}

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

.library-page {
  display: grid;
  gap: 1rem;
  padding: 1rem;
  box-sizing: border-box;
}

.library-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.library-header h1 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
  white-space: nowrap;
}

.library-brand h1 {
  margin: 0;
}

.page-brand h1 {
  margin: 0;
}

.library-search {
  flex: 1 1 28rem;
  display: grid;
  gap: 0.35rem;
  max-width: 34rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.library-search input {
  width: 100%;
}

.library-add-button {
  min-width: 2.4rem;
  padding-inline: 0;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
}

.library-results {
  min-width: 0;
}

.play-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 16rem));
  justify-content: start;
}

.play-card {
  width: 100%;
  max-width: 16rem;
  min-width: 0;
}

.play-card__link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.play-card__body {
  height: 100%;
  display: grid;
  gap: 0.85rem;
  padding: 0.8rem;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.play-card__link {
  cursor: pointer;
}

.play-card__link:hover .play-card__body,
.play-card__link:focus-visible .play-card__body {
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08), var(--shadow-soft);
}

.play-card__link:focus-visible {
  outline: none;
}

.play-card__preview {
  display: grid;
  place-items: center;
  min-height: 6.75rem;
  padding: 0.5rem;
  border-radius: calc(var(--radius-lg) - 4px);
  border: 1px dashed var(--border-strong);
  background: var(--surface-2);
  overflow: hidden;
}

.play-card__preview-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: calc(var(--radius-lg) - 6px);
}

.play-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.play-card__title-group {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.play-card__title-group h2 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
}

.play-card__title-group a {
  color: var(--text);
  text-decoration: none;
}

.play-card__title-group a:hover {
  text-decoration: underline;
}

.play-card__meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.play-card__author {
  margin: 0;
  color: var(--text);
  font-size: 0.92rem;
}

.play-card__description {
  margin: 0;
  color: var(--text);
  line-height: 1.5;
}

.play-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.play-card__source {
  font-size: 0.82rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.play-card__source a {
  color: var(--text);
  font-weight: 600;
}

.play-card__source--empty {
  font-style: italic;
}

.library-empty {
  display: grid;
  gap: 0.75rem;
  padding: 1.25rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.7);
}

.library-empty h2 {
  margin: 0;
  font-size: 1.1rem;
}

.library-empty p {
  margin: 0;
  max-width: 34rem;
  color: var(--muted);
}

.library-modal {
  width: min(100%, 32rem);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.library-modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.library-modal__form {
  display: grid;
  gap: 0.85rem;
  padding: 1.1rem;
}

.library-modal__form h2,
.library-modal__text {
  margin: 0;
}

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

.library-modal__form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.92rem;
}

.library-modal__form input,
.library-modal__form select {
  width: 100%;
}

.library-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.library-modal__cancel {
  background: var(--surface-2);
}

.player-shell,
.editor-shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.82fr);
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.canvas-pane {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: linear-gradient(180deg, #f8fafc, #eef2f7);
  border-right: 1px solid var(--border);
}

.canvas-pane canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #fff;
}

.context-menu {
  position: absolute;
  z-index: 20;
  display: grid;
  gap: 0.45rem;
  min-width: 12rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
}

.context-menu button {
  width: 100%;
  justify-content: flex-start;
  border-radius: 12px;
  background: var(--surface-2);
  box-shadow: none;
  white-space: nowrap;
}

.context-menu .is-active {
  border-color: rgba(37, 99, 235, 0.35);
  background: rgba(37, 99, 235, 0.12);
}

.context-menu__submenu {
  display: grid;
  gap: 0.35rem;
}

.context-menu__submenu > summary {
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  font-weight: 600;
}

.context-menu__submenu > summary::-webkit-details-marker {
  display: none;
}

.context-menu__submenu[open] > summary {
  border-color: rgba(37, 99, 235, 0.35);
}

.context-menu__submenu-items {
  display: grid;
  gap: 0.35rem;
  padding-left: 0.35rem;
}

.player-sidebar,
.editor-sidebar {
  display: grid;
  gap: 0.85rem;
  align-content: start;
  min-height: 0;
  overflow: auto;
  background: transparent;
  backdrop-filter: none;
  border: 0;
  border-radius: 0;
  padding: 1rem;
  box-shadow: none;
}

.panel-header h2 {
  margin: 0;
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.player-step-meta,
.editor-step-meta {
  display: grid;
  gap: 0.55rem;
}

.player-step-title {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.2;
}

.player-step-description {
  margin: 0;
  color: var(--muted);
}

#player-step-description,
#editor-step-description {
  min-height: 6rem;
}

#editor-step-label,
#editor-step-description,
#editor-save-name {
  width: 100%;
  box-sizing: border-box;
}

.editor-save-state {
  padding-top: 0.25rem;
}

.editor-save-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.player-nav-row,
.editor-nav-row,
.editor-actions {
  display: grid;
  gap: 0.5rem;
}

.player-nav-row {
  grid-template-columns: 1fr 1fr 1fr;
}

.editor-nav-row {
  grid-template-columns: repeat(3, 1fr);
}

.editor-actions {
  grid-template-columns: 1fr 1fr;
}

.player-nav-row button,
.editor-nav-row button,
.editor-actions button {
  border-radius: 12px;
  font-weight: 600;
  background: var(--surface-2);
}

.player-nav-row button:disabled,
.editor-nav-row button:disabled,
.editor-actions button:disabled,
button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

@media (max-width: 900px) {
  .library-page {
    padding: 0.75rem;
  }

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

  .library-search {
    order: 3;
    flex-basis: 100%;
    max-width: none;
  }

  .library-body {
    grid-template-columns: 1fr;
  }

  .player-shell,
  .editor-shell {
    grid-template-columns: 1fr;
  }

  .canvas-pane {
    min-height: 320px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .page-topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .page-actions {
    width: 100%;
  }

  .page-actions > * {
    flex: 1 1 auto;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .library-header {
    padding: 0.85rem;
  }

  .library-header h1 {
    white-space: normal;
  }

  .page-actions {
    display: none;
  }
}

/* Tailwind-backed library refresh */
.library-page {
  @apply min-h-screen px-4 py-6 text-slate-100;
  background:
    radial-gradient(circle at top, rgba(56, 189, 248, 0.18), transparent 38%),
    linear-gradient(180deg, #020617 0%, #0f172a 100%);
}

.library-header {
  @apply flex flex-wrap items-center gap-3 rounded-3xl border border-slate-800/80 bg-slate-900/85 p-4 shadow-soft backdrop-blur;
}

.library-brand {
  @apply flex-none;
}

.library-brand__name,
.library-brand h1 {
  @apply text-xl font-semibold tracking-tight text-white;
}

.library-auth {
  @apply ml-auto flex flex-none flex-wrap items-center gap-3;
}

.library-auth__status {
  @apply text-sm text-slate-300;
}

.library-auth__link,
.library-auth__button {
  @apply inline-flex items-center justify-center rounded-full border border-slate-700 bg-slate-800 px-4 py-2 text-sm font-medium text-slate-100 transition hover:-translate-y-0.5 hover:border-slate-500 hover:bg-slate-700 hover:no-underline;
}

.library-search {
  @apply min-w-[16rem] flex-1 gap-2 md:max-w-2xl;
}

.library-search input {
  @apply w-full rounded-full border-slate-700 bg-slate-950/70 px-4 py-3 text-slate-100 placeholder-slate-500 shadow-none focus:border-cyan-400 focus:ring-4 focus:ring-cyan-500/15;
}

.library-add-button {
  @apply flex-none rounded-full border-slate-700 bg-cyan-400 px-4 py-2.5 text-base font-semibold text-slate-950 shadow-none hover:bg-cyan-300;
}

.library-body {
  @apply grid gap-6;
  grid-template-columns: minmax(16rem, 18rem) minmax(0, 1fr);
}

.library-filters {
  @apply rounded-3xl border border-slate-800 bg-slate-900/80 p-5 shadow-soft;
}

.library-filters__header h2 {
  @apply text-xs font-semibold uppercase tracking-widest text-slate-400;
}

.library-filters__header p,
.library-empty p,
.play-card__meta,
.play-card__source,
.library-modal__text {
  @apply text-slate-400;
}

.filter-chip {
  @apply justify-start rounded-2xl border-slate-800 bg-slate-950/80 text-slate-100 shadow-none;
}

.filter-chip.is-active {
  @apply border-cyan-400/60 bg-cyan-400/15 text-cyan-200;
}

.library-results {
  @apply min-w-0;
}

.play-grid {
  @apply grid gap-4;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
}

.play-card__body {
  @apply rounded-3xl border border-slate-800 bg-slate-900/80 p-4 shadow-soft transition;
}

.play-card__link:hover .play-card__body,
.play-card__link:focus-visible .play-card__body {
  @apply -translate-y-1 border-cyan-400/40 shadow-2xl;
}

.play-card__preview {
  @apply min-h-32 rounded-2xl border border-slate-700 bg-slate-950/70 p-3;
}

.play-card__preview-image {
  @apply rounded-2xl;
}

.play-card__title-group h2 {
  @apply text-lg font-semibold tracking-tight text-white;
}

.play-card__author {
  @apply text-sm text-slate-200;
}

.play-card__description {
  @apply text-sm leading-6 text-slate-300;
}

.play-card__footer {
  @apply items-start;
}

.library-empty {
  @apply rounded-3xl border border-dashed border-slate-800 bg-slate-900/70 p-6;
}

.library-empty h2 {
  @apply text-xl font-semibold text-white;
}

.library-modal {
  @apply rounded-3xl border border-slate-800 bg-slate-950 text-slate-100 shadow-2xl;
}

.library-modal::backdrop {
  background: rgba(2, 6, 23, 0.72);
}

.library-modal__form {
  @apply gap-4 p-6;
}

.library-modal__form h2 {
  @apply text-xl font-semibold tracking-tight text-white;
}

.library-modal__form input,
.library-modal__form select {
  @apply rounded-2xl border-slate-700 bg-slate-900 text-slate-100 shadow-none focus:border-cyan-400 focus:ring-4 focus:ring-cyan-500/15;
}

.library-modal__actions {
  @apply pt-1;
}

.library-modal__cancel {
  @apply bg-slate-900 text-slate-100;
}

@media (max-width: 900px) {
  .library-page {
    @apply px-3 py-4;
  }

  .library-body {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .library-header {
    @apply items-stretch;
  }

  .library-brand,
  .library-search,
  .library-auth {
    width: 100%;
  }

  .library-search {
    min-width: 0;
  }

  .library-auth {
    @apply justify-between;
    margin-left: 0;
  }

  .library-brand__name,
  .library-brand h1 {
    @apply text-lg;
  }
}
