:root {
  --bg: #f5f0e8;
  --paper: #fffdf8;
  --line: #d6cab8;
  --line-strong: #ab9d88;
  --ink: #221b14;
  --ink-soft: #655c52;
  --accent: #3959c9;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(circle at 8% 8%, #f7dab6, transparent 34%),
    radial-gradient(circle at 90% 10%, #f5dbc9, transparent 32%),
    linear-gradient(155deg, #f4ede2 0%, #f0e5d2 100%);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  color: var(--ink);
}

.screen-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.screen-card {
  width: min(920px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}

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

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

.auth-error {
  min-height: 1.2rem;
  color: #b42318;
}

.chooser-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.9rem;
}

.chooser-list {
  display: grid;
  gap: 0.5rem;
}

.admin-panel {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  background: #fffef9;
}

.admin-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  align-items: end;
}

.admin-user-list {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.admin-user-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0.55rem;
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: center;
}

.admin-user-meta {
  display: grid;
  gap: 0.15rem;
}

.admin-user-meta span {
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.admin-user-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.danger-btn {
  background: #c0392b;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.danger-btn:hover {
  background: #a93226;
}

.chooser-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
  background: #fff;
}

.chooser-item-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-shrink: 0;
}

.chooser-item-title {
  margin: 0;
  font-size: 1rem;
}

.chooser-item-meta {
  margin: 0.2rem 0 0;
  color: var(--ink-soft);
  font-size: 0.86rem;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
}

.icon-btn:hover {
  border-color: var(--accent);
  background: #f0f3ff;
}

.settings-modal-content {
  max-width: 520px;
}

.new-choreo-modal-content {
  max-width: 560px;
}

.settings-modal-content .settings-content {
  display: grid;
  gap: 0.8rem;
}

.user-badge {
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.readonly-mode .settings-content input,
.readonly-mode .settings-content select,
.readonly-mode .settings-content button,
.readonly-mode .settings-content .dancer-row-btn,
.readonly-mode #save-btn,
.readonly-mode #add-batch-btn,
.readonly-mode #remove-count-btn,
.readonly-mode #quick-add-batch-btn,
.readonly-mode #quick-remove-count-btn {
  pointer-events: none;
  opacity: 0.6;
}

/* Dancer mode is pure playback/navigation: no editor controls, no settings sidebar. */
.dancer-view .sidebar,
.dancer-view .batch-bar,
.dancer-view .multi-hint,
.dancer-view .timeline-quick-batch,
.dancer-view #save-btn,
.dancer-view #load-btn {
  display: none !important;
}

.dancer-view .layout {
  grid-template-columns: 1fr;
}

.dancer-view .stage-area {
  grid-template-rows: auto 1fr;
}

.dancer-view .canvas-timeline-grid {
  max-height: none;
  height: calc(100vh - 170px);
  min-height: 520px;
  grid-template-columns: 1fr 190px;
}

.dancer-view .stage-wrap,
.dancer-view .timeline-sidebar {
  max-height: none;
  height: 100%;
}

.dancer-view #stage-canvas {
  cursor: default;
}

.app {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
  background: #fff8ee;
}

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
}

.topbar p {
  margin: 0.3rem 0 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.layout {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.8rem;
  padding: 0.8rem;
  min-height: 0;
}

.sidebar {
  display: none;
}

.settings-card {
  padding: 0;
  overflow: hidden;
}

.settings-panel {
  display: grid;
}

.settings-summary {
  list-style: none;
  cursor: pointer;
  padding: 0.75rem 0.85rem;
  display: grid;
  gap: 0.12rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff8ee 0%, #f8ecdb 100%);
}

.settings-summary::-webkit-details-marker {
  display: none;
}

.settings-summary-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}

.settings-summary-subtitle {
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.settings-panel:not([open]) .settings-summary {
  border-bottom: none;
}

.settings-content {
  display: grid;
  gap: 0.7rem;
  padding: 0.72rem;
}

.settings-block {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.72rem;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem;
}

.card h2 {
  margin: 0 0 0.65rem;
  font-size: 1rem;
}

.settings-block h2 {
  margin: 0 0 0.65rem;
  font-size: 1rem;
}

.pair-controls {
  display: grid;
  gap: 0.45rem;
}

label {
  display: grid;
  gap: 0.2rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

input,
select,
button {
  font: inherit;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0.42rem 0.55rem;
  background: #fff;
}

button {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  padding: 0.42rem 0.62rem;
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.legend {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.6rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 1px solid #00000050;
}

.bank-list {
  display: grid;
  gap: 0.4rem;
  align-content: start;
  justify-items: center;
  max-height: 100%;
  overflow-y: auto;
  padding-right: 0.12rem;
}

.bank-token {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid #00000033;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: grab;
  padding: 0;
}

.bank-token.male {
  background: #4f81e8;
  color: #fff;
}

.bank-token.female {
  background: #e25d77;
  color: #fff;
}

.bank-token.selected {
  box-shadow: 0 0 0 3px #1f3ea8;
}

.bank-empty {
  color: var(--ink-soft);
  font-size: 0.9rem;
  padding: 0.2rem;
}

.field-grid {
  display: grid;
  gap: 0.45rem;
}

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

.button-row {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.preset-row {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.floor-row {
  display: grid;
  gap: 0.45rem;
  grid-template-columns: 1fr 1fr;
}

.new-choreo-form {
  display: grid;
  gap: 0.8rem;
}

.button-row button[data-playing="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.small-note {
  margin: 0.55rem 0 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.multi-hint {
  margin-top: -0.15rem;
}

.stage-area {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 0.6rem;
}

.stage-zone {
  min-height: 0;
  display: grid;
  grid-template-columns: 62px 1fr 62px;
  gap: 0.6rem;
}

.bank-column {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0.35rem;
  padding: 0.35rem 0.2rem;
  min-height: 0;
}

.bank-column h4 {
  margin: 0;
  text-align: center;
  font-size: 0.7rem;
  color: var(--ink-soft);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.canvas-timeline-grid {
  display: grid;
  grid-template-columns: 1fr 210px;
  gap: 0.8rem;
  min-height: 0;
  height: auto;
  max-height: clamp(260px, 52vh, 520px);
  position: relative;
}

.fullscreen-exit-btn {
  display: none;
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  z-index: 1501;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid #0000002a;
  background: rgba(0, 0, 0, 0.68);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  align-items: center;
  justify-content: center;
}

.fullscreen-exit-btn:hover {
  background: rgba(0, 0, 0, 0.82);
}

.timeline-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  max-height: clamp(260px, 52vh, 520px);
}

.timeline-title {
  margin: 0;
  font-size: 0.95rem;
  color: var(--ink);
  font-weight: 600;
  padding: 0 0.3rem;
  flex-shrink: 0;
}

.timeline-quick-batch {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem;
  background: #fffef9;
  display: grid;
  gap: 0.35rem;
  flex-shrink: 0;
}

.timeline-quick-batch label {
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.timeline-quick-batch input {
  min-height: 36px;
}

.timeline-quick-batch button {
  min-height: 36px;
  font-size: 0.88rem;
}

.timeline-quick-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
}

.batch-bar {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffaf2;
  padding: 0.55rem;
  display: grid;
  gap: 0.5rem;
}

.batch-bar .small-note {
  margin-top: 0;
}

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

.current-count {
  font-size: 0.96rem;
}

.stage-wrap {
  height: clamp(260px, 52vh, 520px);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #fff8ef 0%, #f7ebd8 100%);
  overflow: hidden;
  touch-action: none;
}

#stage-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

#fullscreen-btn[data-active="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.canvas-timeline-grid:fullscreen {
  width: 100vw;
  height: 100vh;
  max-height: none;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 0.8rem;
  padding: 0.8rem;
  background: #f6ecdc;
}

.canvas-timeline-grid:fullscreen .fullscreen-exit-btn {
  display: inline-flex;
}

.canvas-timeline-grid:fullscreen .stage-wrap {
  height: 100%;
  max-height: none;
}

.canvas-timeline-grid:fullscreen .timeline-sidebar {
  height: 100%;
  max-height: none;
}

.canvas-timeline-grid:fullscreen .timeline {
  min-height: 0;
}

.canvas-timeline-grid.stage-expanded {
  position: fixed;
  inset: 0;
  z-index: 1400;
  width: 100vw;
  height: 100vh;
  max-height: none;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 0.8rem;
  padding: 0.8rem;
  background: #f6ecdc;
}

.canvas-timeline-grid.stage-expanded .fullscreen-exit-btn {
  display: inline-flex;
}

.canvas-timeline-grid.stage-expanded .stage-wrap {
  height: 100%;
  max-height: none;
}

.canvas-timeline-grid.stage-expanded .timeline-sidebar {
  height: 100%;
  max-height: none;
}

.canvas-timeline-grid.stage-expanded .timeline {
  min-height: 0;
}

body.stage-expanded {
  overflow: hidden;
}

.timeline {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffaf2;
  padding: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 200px;
}

.batch-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.batch-counts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
}

/* Scrollbar Styling */
.timeline::-webkit-scrollbar {
  width: 8px;
}

.timeline::-webkit-scrollbar-track {
  background: transparent;
}

.timeline::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 4px;
}

.timeline::-webkit-scrollbar-thumb:hover {
  background: var(--ink-soft);
}

.bank-empty {
  margin: 0.45rem 0 0;
  color: var(--ink-soft);
  font-size: 0.86rem;
}

.batch-label {
  font-size: 0.8rem;
  color: var(--ink);
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  letter-spacing: 0.3px;
  gap: 0.5rem;
}

.batch-label-text {
  flex: 1;
  text-align: center;
}

.batch-delete-btn {
  background: #dc2626;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 600;
  line-height: 1;
}

.batch-delete-btn:hover {
  background: #b91c1c;
  transform: scale(1.05);
}

.batch-group:first-child .batch-label {
  margin-top: 0;
}

.count-chip {
  min-width: 0;
  aspect-ratio: 1;
  padding: 0.45rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 0.85rem;
}

.count-chip:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.count-chip.selected {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

/* ============================================================================
   Topbar Buttons (Save/Load)
   ============================================================================ */

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

.topbar-left {
  flex: 1;
}

.topbar-right {
  display: flex;
  gap: 0.5rem;
}

.primary-btn,
.secondary-btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.primary-btn {
  background: #2d8659;
  color: white;
}

.primary-btn:hover {
  background: #247049;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(45, 134, 89, 0.3);
}

.secondary-btn {
  background: var(--accent);
  color: white;
}

.secondary-btn:hover {
  background: #2a44a8;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(57, 89, 201, 0.3);
}

/* ============================================================================
   Modal Dialog
   ============================================================================ */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--paper);
  border-radius: 14px;
  border: 2px solid var(--line-strong);
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  animation: slideIn 0.3s;
}

#save-modal .modal-content {
  max-width: 500px;
}

@keyframes slideIn {
  from { 
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--line);
}

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

.close-btn {
  background: none;
  border: none;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-soft);
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
}

.close-btn:hover {
  background: var(--line);
  color: var(--ink);
}

.modal-body {
  padding: 1.2rem;
  overflow-y: auto;
  flex: 1;
}

/* ============================================================================
   Choreography List in Modal
   ============================================================================ */

#choreo-list {
  display: grid;
  gap: 0.8rem;
}

.choreo-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
  display: grid;
  gap: 0.6rem;
}

.choreo-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.choreo-item-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
  color: var(--ink);
}

.choreo-item-meta {
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 0;
}

.choreo-item-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.choreo-item-actions button {
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: white;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.choreo-item-actions button:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.choreo-item-actions button.load-btn {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.choreo-item-actions button.load-btn:hover {
  background: #2a44a8;
}

.choreo-item-actions button.duplicate-btn {
  background: #e8a040;
  color: white;
  border-color: #e8a040;
}

.choreo-item-actions button.duplicate-btn:hover {
  background: #d18f30;
}

.choreo-item-actions button.delete-btn {
  background: #d64545;
  color: white;
  border-color: #d64545;
}

.choreo-item-actions button.delete-btn:hover {
  background: #b83535;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--ink-soft);
}

.empty-state p {
  margin: 0.5rem 0;
}

/* ============================================================================
   Save Form in Modal
   ============================================================================ */

.form-group {
  margin-bottom: 1.2rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 500;
  color: var(--ink);
}

.form-group input[type="text"],
.form-group textarea {
  width: 100%;
  padding: 0.6rem;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.95rem;
  transition: border 0.2s;
}

.form-group input[type="text"]:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(57, 89, 201, 0.1);
}

.form-group textarea {
  resize: vertical;
}

.form-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.form-actions button {
  flex: 1;
  max-width: 150px;
}

@media (max-width: 980px) {
  body.dancer-view {
    overflow: hidden;
  }

  .dancer-view .app {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  .dancer-view .layout {
    height: 100%;
    min-height: 0;
    overflow: hidden;
    padding-bottom: 0.4rem;
  }

  .dancer-view .stage-area {
    height: 100%;
    min-height: 0;
    overflow: hidden;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .admin-form {
    grid-template-columns: 1fr;
  }

  .admin-user-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .admin-user-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .batch-bar {
    display: none;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .stage-area {
    order: 1;
  }

  .sidebar {
    order: 2;
    margin-top: 0.1rem;
  }

  .canvas-timeline-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    max-height: none;
    gap: 0.6rem;
  }

  .stage-zone {
    grid-template-columns: 52px 1fr 52px;
    gap: 0.45rem;
  }

  .bank-token {
    width: 34px;
    height: 34px;
    font-size: 0.78rem;
  }

  .timeline-sidebar {
    max-height: none;
    order: 1;
    overflow: visible;
  }

  .timeline-title {
    font-size: 1.05rem;
    font-weight: 700;
  }

  .batch-counts {
    grid-template-columns: repeat(auto-fill, minmax(34px, 44px));
    gap: 0.28rem;
  }

  .count-chip {
    padding: 0.12rem;
    font-size: 0.68rem;
    border-radius: 6px;
  }

  .batch-label {
    padding: 0.18rem 0.32rem;
    font-size: 0.66rem;
    border-radius: 6px;
    gap: 0.28rem;
    letter-spacing: 0.15px;
  }

  .batch-delete-btn {
    padding: 0.1rem 0.26rem;
    font-size: 0.56rem;
  }

  .stage-wrap {
    height: clamp(340px, 58vh, 560px);
    order: 2;
  }

  .timeline {
    min-height: 120px !important;
    max-height: 24vh;
    padding: 0.42rem;
    gap: 0.45rem;
  }

  .timeline-quick-batch {
    padding: 0.38rem;
    gap: 0.28rem;
  }

  .timeline-quick-batch label {
    font-size: 0.72rem;
  }

  .timeline-quick-batch input,
  .timeline-quick-batch button {
    min-height: 32px;
    font-size: 0.8rem;
  }

  .stage-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .stage-top .button-row {
    width: 100%;
  }

  .stage-top .button-row button {
    flex: 1 1 calc(50% - 0.25rem);
    min-height: 42px;
  }

  .batch-bar .button-row button {
    flex: 1;
    min-height: 42px;
  }

  .settings-summary {
    padding: 0.85rem 0.9rem;
  }

  .settings-summary-title {
    font-size: 1.02rem;
  }

  .settings-content {
    padding-top: 0.4rem;
  }

  .canvas-timeline-grid:fullscreen,
  .canvas-timeline-grid.stage-expanded {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .canvas-timeline-grid:fullscreen .timeline-sidebar,
  .canvas-timeline-grid.stage-expanded .timeline-sidebar {
    max-height: none;
  }

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

  .topbar-right {
    width: 100%;
  }

  .primary-btn,
  .secondary-btn {
    flex: 1;
  }

  .dancer-view .topbar-left p {
    display: none;
  }

  .dancer-view .topbar-right {
    width: auto;
  }

  .dancer-view .stage-top {
    gap: 0.55rem;
  }

  .dancer-view .stage-top .button-row button {
    min-height: 48px;
    font-size: 1rem;
  }

  .dancer-view .canvas-timeline-grid {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    height: 100%;
    min-height: 0;
    gap: 0.45rem;
    width: 100%;
    min-width: 0;
    overflow: hidden;
  }

  .dancer-view .stage-wrap {
    order: 1;
    height: auto;
    min-height: 0;
    max-height: none;
  }

  .dancer-view .timeline-sidebar {
    order: 2;
    height: min(30vh, 260px);
    max-height: min(30vh, 260px);
    overflow: hidden;
    position: sticky;
    bottom: 0;
    background: #f0e5d2;
    padding-bottom: 0.35rem;
    z-index: 2;
    width: 100%;
    min-width: 0;
  }

  .dancer-view .timeline {
    min-height: 0 !important;
    height: 100%;
    max-height: 100%;
    overflow-x: auto;
    overflow-y: auto;
    white-space: normal;
    display: flex;
    flex-wrap: nowrap;
    padding: 0.4rem;
    width: 100%;
    min-width: 0;
  }

  .dancer-view .batch-group {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    min-width: max-content;
    margin-right: 0.5rem;
    gap: 0.3rem;
  }

  .dancer-view .batch-counts {
    display: flex;
    gap: 0.3rem;
    grid-template-columns: none;
  }

  .dancer-view .count-chip {
    width: 46px;
    height: 46px;
    aspect-ratio: auto;
    flex: 0 0 auto;
    font-size: 0.9rem;
    border-radius: 10px;
  }

  .dancer-view .stage-top,
  .dancer-view .stage-top .button-row,
  .dancer-view .current-count,
  .dancer-view .timeline-title {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 980px) and (orientation: landscape) {
  .canvas-timeline-grid:fullscreen,
  .canvas-timeline-grid.stage-expanded {
    grid-template-columns: minmax(0, 1fr) clamp(210px, 34vw, 280px);
    grid-template-rows: 1fr;
    gap: 0.55rem;
    padding: 0.55rem;
  }

  .canvas-timeline-grid:fullscreen .stage-wrap,
  .canvas-timeline-grid.stage-expanded .stage-wrap {
    order: 1;
    height: 100%;
    max-height: none;
  }

  .canvas-timeline-grid:fullscreen .timeline-sidebar,
  .canvas-timeline-grid.stage-expanded .timeline-sidebar {
    order: 2;
    height: 100%;
    min-height: 0;
    max-height: none;
    overflow: hidden;
  }

  .canvas-timeline-grid:fullscreen .timeline,
  .canvas-timeline-grid.stage-expanded .timeline {
    min-height: 0 !important;
    max-height: none;
  }

  .canvas-timeline-grid:fullscreen .timeline-title,
  .canvas-timeline-grid.stage-expanded .timeline-title {
    font-size: 0.92rem;
  }

  .canvas-timeline-grid:fullscreen .timeline-quick-batch,
  .canvas-timeline-grid.stage-expanded .timeline-quick-batch {
    padding: 0.3rem;
    gap: 0.2rem;
  }

  .canvas-timeline-grid:fullscreen .timeline-quick-batch label,
  .canvas-timeline-grid.stage-expanded .timeline-quick-batch label {
    font-size: 0.66rem;
  }

  .canvas-timeline-grid:fullscreen .timeline-quick-batch input,
  .canvas-timeline-grid.stage-expanded .timeline-quick-batch input,
  .canvas-timeline-grid:fullscreen .timeline-quick-batch button,
  .canvas-timeline-grid.stage-expanded .timeline-quick-batch button {
    min-height: 28px;
    font-size: 0.74rem;
    padding: 0.2rem 0.35rem;
  }

  .canvas-timeline-grid:fullscreen .batch-counts,
  .canvas-timeline-grid.stage-expanded .batch-counts {
    grid-template-columns: repeat(auto-fill, minmax(30px, 40px));
    gap: 0.22rem;
  }

  .canvas-timeline-grid:fullscreen .count-chip,
  .canvas-timeline-grid.stage-expanded .count-chip {
    font-size: 0.62rem;
    padding: 0.08rem;
  }

  .canvas-timeline-grid:fullscreen .batch-label,
  .canvas-timeline-grid.stage-expanded .batch-label {
    font-size: 0.6rem;
    padding: 0.12rem 0.26rem;
  }

  .canvas-timeline-grid:fullscreen .batch-delete-btn,
  .canvas-timeline-grid.stage-expanded .batch-delete-btn {
    font-size: 0.5rem;
    padding: 0.06rem 0.2rem;
  }

  .dancer-view .topbar {
    padding: 0.45rem 0.7rem;
  }

  .dancer-view .topbar h1 {
    font-size: 1.05rem;
  }

  .dancer-view .stage-top {
    gap: 0.35rem;
  }

  .dancer-view .stage-top .button-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
    gap: 0.35rem;
  }

  .dancer-view .stage-top .button-row button {
    min-height: 36px;
    font-size: 0.9rem;
  }

  .dancer-view .stage-area {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .dancer-view .canvas-timeline-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 190px;
    grid-template-rows: 1fr;
    height: calc(100dvh - 170px);
    min-height: 180px;
    overflow: hidden;
  }

  .dancer-view .stage-wrap {
    order: 1;
    height: 100%;
    max-height: none;
    min-height: 0;
  }

  .dancer-view .timeline-sidebar {
    order: 2;
    position: static;
    height: 100%;
    max-height: none;
    min-height: 0;
    background: transparent;
    padding-bottom: 0;
    overflow: hidden;
  }

  .dancer-view .timeline {
    height: 100%;
    max-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    white-space: normal;
  }

  .dancer-view .batch-group {
    margin-right: 0;
    min-width: 0;
  }

  .dancer-view .batch-counts {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.24rem;
  }

  .dancer-view .count-chip {
    width: auto;
    height: 34px;
    font-size: 0.8rem;
  }
}
