:root {
  --bg: #0a0d14;
  --bg-elev: #12172a;
  --bg-soft: #1a2140;
  --paper: #fff8ee;
  --ink: #1b140c;
  --muted: #8b93a7;
  --muted-ink: #6b6358;
  --line: #2a3354;
  --accent: #ff5c2b;
  --accent-2: #7c5cff;
  --chord: #d63a12;
  --ok: #3dcc8a;
  --err: #ff6b7a;
  --shadow: rgba(0, 0, 0, 0.28);
  --fw: 1.45rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --radius: 14px;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans TC", system-ui, sans-serif;
  background:
    radial-gradient(900px 420px at 10% -10%, rgba(255, 92, 43, 0.16), transparent 55%),
    radial-gradient(700px 380px at 90% 0%, rgba(124, 92, 255, 0.12), transparent 50%),
    var(--bg);
  color: #eef1f8;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding:
    calc(1rem + var(--safe-top))
    calc(1rem + var(--safe-right))
    calc(5.5rem + var(--safe-bottom))
    calc(1rem + var(--safe-left));
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.8rem;
  align-items: center;
  margin-bottom: 1.4rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 9px;
  background:
    linear-gradient(#ff5c2b, #ff5c2b) 30% 68% / 12% 42% no-repeat,
    linear-gradient(#ff5c2b, #ff5c2b) 50% 55% / 12% 28% no-repeat,
    linear-gradient(#ff5c2b, #ff5c2b) 70% 68% / 12% 42% no-repeat,
    #161b2e;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.brand-text {
  display: grid;
}

.brand-text strong {
  font-family: Syne, "Noto Sans TC", sans-serif;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

.brand-text small {
  color: var(--muted);
  font-size: 0.72rem;
}

.top-search input,
.auth-form input,
.song-search,
.song-select,
.admin-page input,
.admin-page textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  color: inherit;
  font: inherit;
  padding: 0.55rem 0.8rem;
}

.top-search input::placeholder,
.auth-form input::placeholder {
  color: #6d7690;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.auth-user {
  color: var(--muted);
  font-size: 0.86rem;
}

.ghost-btn,
.text-btn,
.primary-btn,
.chip,
.tp-btn,
.song-card-action,
.mobile-nav-btn {
  font: inherit;
  cursor: pointer;
}

.ghost-btn,
.chip,
.song-card-action {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(18, 23, 42, 0.86);
  color: inherit;
  padding: 0.35rem 0.75rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ghost-btn:hover,
.chip:hover,
.song-card-action:hover {
  border-color: #4a5680;
  background: var(--bg-soft);
}

.primary-btn {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.2rem 0.35rem;
}

.hero {
  margin: 0 0 1.6rem;
}

.eyebrow {
  margin: 0 0 0.4rem;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

.hero h1 {
  margin: 0;
  font-family: Syne, "Noto Sans TC", sans-serif;
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1.15;
}

.hero-copy {
  max-width: 38rem;
  color: var(--muted);
  margin: 0.7rem 0 0;
}

.home-strip {
  margin-bottom: 1.2rem;
}

.home-strip h2,
.sidebar h2,
.auth-drawer h2 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
}

.song-row {
  display: flex;
  gap: 0.7rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
}

.song-row-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.song-card {
  flex: 0 0 220px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  padding: 0.75rem;
}

.song-card--active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 92, 43, 0.35);
}

.song-card-title {
  all: unset;
  display: block;
  width: 100%;
  cursor: pointer;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.song-card-title:hover,
.song-card-title:focus-visible {
  color: var(--accent);
}

.song-card-meta {
  margin: 0.35rem 0 0.6rem;
  color: var(--muted);
  font-size: 0.8rem;
  min-height: 2.2em;
}

.song-card-action:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.song-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-bottom: 0.9rem;
}

.song-heading h1 {
  margin: 0;
  font-size: clamp(1.4rem, 3vw, 2rem);
}

.song-heading p {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.toolbar-actions {
  display: flex;
  gap: 0.45rem;
}

.transport {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.4rem;
  align-items: end;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(18, 23, 42, 0.9);
  margin-bottom: 1rem;
  position: sticky;
  top: 0.6rem;
  z-index: 3;
}

.field-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.transport-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tp-btn {
  min-width: 40px;
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: inherit;
}

.tp-value {
  min-width: 2.2rem;
  text-align: center;
  font-weight: 700;
}

.song-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(4.5rem, auto));
  gap: 0.15rem 1rem;
  margin: 0;
}

.song-meta dt {
  color: var(--muted);
  font-size: 0.72rem;
}

.song-meta dd {
  margin: 0;
  font-weight: 700;
}

.song-layout {
  display: grid;
  gap: 1rem;
}

.sidebar {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  padding: 0.9rem;
}

.chord-palette-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.diagram-panel {
  margin-top: 0.9rem;
  padding-top: 0.8rem;
  border-top: 1px dashed var(--line);
}

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

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

.sheet-wrap {
  min-width: 0;
}

.sheet {
  background: var(--paper);
  color: var(--ink);
  border-radius: 18px;
  padding: clamp(1rem, 3vw, 1.6rem);
  box-shadow: 0 16px 50px var(--shadow);
  min-height: 24rem;
}

.sheet-empty {
  margin: 0;
  color: var(--muted-ink);
}

.section + .section {
  margin-top: 1.3rem;
}

.section-label {
  margin: 0 0 0.55rem;
  color: #8a4b2a;
  font-size: 0.92rem;
}

.lyric-line {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.15rem 0.35rem;
  margin-bottom: 0.7rem;
}

.cell {
  display: grid;
  justify-items: start;
}

.chord-name {
  min-height: 1.2em;
  color: var(--chord);
  font-weight: 700;
}

.chord-name button {
  all: unset;
  cursor: pointer;
  color: inherit;
}

.chord-name button:hover,
.chord-name button:focus-visible {
  text-decoration: underline;
}

.chord-name--empty {
  color: #d7c8b5;
}

.lyric {
  font-size: 1em;
}

.lyric-char--mark {
  background: #ffe0c6;
  border-radius: 3px;
}

.fretboard-wrap {
  overflow-x: auto;
}

.fretboard-caption {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
}

.fretboard {
  --fw: 1.45rem;
  display: grid;
  width: max-content;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #0e1324;
}

.fretboard__corner,
.fretboard__nut-head,
.fretboard__fret-num,
.fretboard__label,
.fretboard__cell {
  min-height: 1.6rem;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
}

.fretboard__fret-num,
.fretboard__label {
  color: var(--muted);
  background: #161c32;
}

.fretboard__cell {
  border-top: 1px solid #2c3556;
  border-left: 1px solid #2c3556;
}

.fretboard__cell--nut {
  background: #1b223c;
}

.fretboard__cell--open {
  color: #7ee0b2;
}

.fretboard__cell--mute {
  color: #ff8a96;
}

.fretboard__cell--dot {
  color: var(--accent);
  font-size: 1rem;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 14, 0.62);
  z-index: 20;
}

.auth-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(26rem, 100%);
  height: 100%;
  background: #101628;
  border-left: 1px solid var(--line);
  padding: calc(1rem + var(--safe-top)) 1rem 1.4rem;
  transform: translateX(100%);
  transition: transform 0.22s ease;
  z-index: 21;
}

.auth-drawer.is-open {
  transform: translateX(0);
}

.auth-drawer-head,
.auth-tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.auth-tabs {
  margin: 0.8rem 0;
}

.auth-tab {
  flex: 1;
  min-height: 40px;
  border: 1px solid var(--line);
  background: transparent;
  color: inherit;
  border-radius: 10px;
}

.auth-tab.is-active {
  background: var(--bg-soft);
  border-color: var(--accent);
}

.auth-form {
  display: grid;
  gap: 0.35rem;
}

.auth-form .field-label {
  margin-top: 0.55rem;
}

.auth-msg {
  min-height: 1.3em;
  font-size: 0.9rem;
}

.auth-msg--ok {
  color: var(--ok);
}

.auth-msg--err {
  color: var(--err);
}

.mobile-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.3rem;
  padding: 0.45rem 0.45rem calc(0.45rem + var(--safe-bottom));
  background: rgba(10, 13, 20, 0.94);
  border-top: 1px solid var(--line);
  z-index: 15;
}

.mobile-nav-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  min-height: 42px;
}

.mobile-nav-btn.is-active {
  color: #fff;
  background: var(--bg-soft);
  border-radius: 10px;
}

.admin-page {
  background: var(--bg);
  color: #eef1f8;
}

.admin-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding:
    calc(1rem + var(--safe-top))
    calc(0.9rem + var(--safe-right))
    calc(1.5rem + var(--safe-bottom))
    calc(0.9rem + var(--safe-left));
}

.admin-page .logo {
  font-family: Syne, "Noto Sans TC", sans-serif;
  margin: 0;
}

.admin-page .tagline,
.admin-hint,
.empty-note {
  color: var(--muted);
}

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch;
  margin: 1rem 0 0.6rem;
}

.admin-toolbar > * {
  min-height: 44px;
}

.admin-toolbar .song-select {
  flex: 1 1 220px;
  margin: 0;
}

.admin-toolbar a {
  color: inherit;
}

.admin-msg {
  min-height: 1.25em;
  margin: 0 0 0.8rem;
}

.editor-grid {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 0.9rem;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  padding: 0.8rem;
}

.song-list {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
  max-height: 70vh;
  overflow: auto;
}

.song-list-btn {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #161c32;
  color: inherit;
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  cursor: pointer;
}

.song-list-btn.is-active {
  border-color: var(--accent);
}

.song-list-meta {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.song-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.song-form .field {
  display: grid;
  gap: 0.22rem;
}

.song-form .field.full {
  grid-column: 1 / -1;
}

.sections-wrap,
.lines-wrap,
.cells-wrap {
  margin-top: 0.7rem;
  display: grid;
  gap: 0.7rem;
}

.section-card,
.line-card,
.cell-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #161c32;
  padding: 0.55rem;
}

.line-top,
.cell-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.cell-fields {
  margin-top: 0.45rem;
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) 120px;
  gap: 0.5rem;
}

.cell-mark {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 40px;
}

@media (min-width: 980px) {
  .song-layout {
    grid-template-columns: 250px minmax(0, 1fr);
    align-items: start;
  }

  .sidebar {
    position: sticky;
    top: 6.2rem;
  }

  .mobile-nav {
    display: none;
  }

  .app {
    padding-bottom: 2rem;
  }
}

@media (max-width: 979px) {
  body[data-view="song"][data-panel="sheet"] .sidebar {
    display: none;
  }

  body[data-view="song"][data-panel="tools"] .sheet-wrap {
    display: none;
  }
}

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .song-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .editor-grid,
  .song-form,
  .cell-fields {
    grid-template-columns: 1fr;
  }

  .song-list {
    max-height: 35vh;
  }
}

@media print {
  body {
    background: #fff;
    color: #000;
  }

  .topbar,
  .transport,
  .sidebar,
  .song-toolbar,
  .mobile-nav,
  .auth-drawer,
  .drawer-backdrop {
    display: none !important;
  }

  .app {
    padding: 0;
  }

  .sheet {
    box-shadow: none;
    border-radius: 0;
  }

  .view-home {
    display: none !important;
  }

  .view-song {
    display: block !important;
  }
}
