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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242836;
  --border: #2e3345;
  --text: #e4e6ef;
  --text-muted: #8b90a5;
  --accent: #5b8def;
  --accent-hover: #4a7ae0;
  --danger: #e05555;
  --success: #4caf82;
  --tile-color: #3d5a3e;
  --segment-color: #8b6914;
  --path-line: #ffd166;
  --ground-fill: #2d4a2e;
  --sky: #1a2744;
}

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.save-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0 8px;
  white-space: nowrap;
}

.save-status[data-status="pending"],
.save-status[data-status="saving"] {
  color: var(--accent);
}

.save-status[data-status="saved"] {
  color: #6bcb77;
}

.save-status[data-status="error"] {
  color: #f66;
}

.toolbar-separator {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
  flex-shrink: 0;
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.layout {
  display: grid;
  grid-template-columns:
    var(--panel-left-width, 280px)
    1fr
    var(--panel-game-width, 260px)
    var(--panel-right-width, 300px);
  grid-template-rows: minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

.layout.panel-left-hidden {
  --panel-left-width: 0px;
}

.layout.panel-game-hidden {
  --panel-game-width: 0px;
}

.layout.panel-right-hidden {
  --panel-right-width: 0px;
}

.panel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 16px;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  transition: opacity 0.15s ease;
  overscroll-behavior: contain;
}

.panel.panel-hidden {
  overflow: hidden;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  border-color: transparent;
}

.panel-right {
  border-right: none;
  border-left: 1px solid var(--border);
}

.panel-game {
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel-game-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  margin-bottom: 0;
}

.game-preview-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 0;
  padding-bottom: 12px;
}

.game-preview-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.game-preview-header h2 {
  margin-bottom: 0;
}

.game-preview-away {
  margin: 24px 0 0;
  text-align: center;
  color: var(--text-muted);
}

.game-preview-float {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 20;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  user-select: none;
}

.game-preview-float.hidden {
  display: none;
}

.game-preview-float-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  cursor: grab;
  touch-action: none;
}

.game-preview-float-header:active {
  cursor: grabbing;
}

.game-preview-float-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
}

.game-preview-float-body {
  padding: 8px 10px 4px;
  min-height: 60px;
}

.game-preview-float-body .game-preview-canvas-wrap {
  margin: 0;
  min-height: 0;
}

.game-preview-float-body .game-preview-hint {
  padding: 4px 0 2px;
  font-size: 0.68rem;
}

.game-preview-float-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  touch-action: none;
}

.game-preview-float-resize::after {
  content: '';
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  opacity: 0.7;
}

.game-preview-canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  margin: 12px 0;
}

.game-preview-pos {
  font-size: 0.72rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

#game-preview-canvas {
  display: block;
  max-width: 100%;
  cursor: ew-resize;
  background: var(--sky);
  border-radius: 6px;
}

.game-preview-hint {
  margin: 0;
  text-align: center;
}

.panel-section {
  margin-bottom: 24px;
}

.panel-section h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.panel-section--title {
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.panel-section--title h2 {
  margin-bottom: 0;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-header h2 {
  margin-bottom: 0;
}

.panel-section--collapsible .section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0;
  margin-bottom: 12px;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  text-align: left;
  border-radius: 4px;
}

.panel-section--collapsible .section-toggle:hover h2 {
  color: var(--text);
}

.panel-section--collapsible.is-collapsed .section-toggle {
  margin-bottom: 0;
}

.panel-section--collapsible .section-toggle h2 {
  margin-bottom: 0;
}

.section-toggle-chevron {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  margin-left: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

.panel-section--collapsible.is-collapsed .section-toggle-chevron {
  transform: rotate(-45deg);
}

.panel-section--collapsible.is-collapsed .section-collapse {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 0.85rem;
}

.field span {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.field input[type="number"],
.field input[type="text"],
.field select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 0.85rem;
  width: 100%;
}

.field input[type="range"] {
  width: calc(100% - 40px);
  vertical-align: middle;
}

.range-value {
  display: inline-block;
  width: 36px;
  text-align: right;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: 4px;
}

.hint-warning {
  color: var(--danger);
  margin-top: 8px;
}

.hint-ok {
  color: var(--success);
  margin-top: 8px;
}

.orientation-row {
  margin-top: 0;
}

.btn-orientation {
  flex: 1;
  min-width: 0;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.profile-anchor-list {
  list-style: none;
  margin: 6px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.profile-anchor-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px;
  background: var(--surface-2);
  border-radius: 4px;
  font-size: 0.75rem;
}

.profile-anchor-list button {
  flex-shrink: 0;
}

.btn {
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  margin-top: 8px;
}

.btn-danger:hover {
  background: rgba(224, 85, 85, 0.15);
}

.btn-small {
  padding: 5px 10px;
  font-size: 0.78rem;
}

.btn-active {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
}

.btn-panel-toggle {
  flex-shrink: 0;
  background: transparent;
  color: #c8ccd6;
  border: 1px solid #8b919f;
}

.btn-panel-toggle:hover {
  background: transparent;
  color: #e8eaef;
  border-color: #b8bdc9;
}

.btn-panel-toggle.btn-active {
  background: transparent;
  color: #eef0f4;
  border-color: #d0d4de;
}

.btn-panel-toggle:not(.btn-active) {
  background: transparent;
  color: #7a808f;
  border-color: #5c6270;
  opacity: 0.9;
}

#preview-canvas.cursor-screen {
  cursor: grab;
}

#preview-canvas.cursor-screen:active {
  cursor: grabbing;
}

.lane-list {
  list-style: none;
  margin-bottom: 8px;
}

.lane-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  overflow: hidden;
}

.lane-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  background: var(--surface-2);
  font-size: 0.82rem;
  transition: background 0.12s;
}

.lane-item-header:hover {
  background: var(--border);
}

.lane-item-header.is-active {
  background: rgba(91, 141, 239, 0.14);
  box-shadow: inset 0 0 0 1px rgba(91, 141, 239, 0.45);
}

.lane-item-header.is-active:hover {
  background: rgba(91, 141, 239, 0.2);
}

.lane-item-header.is-selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.lane-item-badge {
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(91, 141, 239, 0.18);
  border-radius: 4px;
  padding: 1px 5px;
}

.lane-item-icon {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--accent);
}

.lane-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lane-item-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.lane-item-meta.warn {
  color: var(--danger);
}

.path-tree {
  list-style: none;
}

.path-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  overflow: hidden;
}

.path-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  background: var(--surface-2);
  font-size: 0.82rem;
  transition: background 0.12s;
}

.path-item-header:hover {
  background: var(--border);
}

.path-item-header.selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.path-item-icon {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.path-item-icon.tile { background: var(--tile-color); }
.path-item-icon.segment { background: var(--segment-color); }

.path-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.path-item-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.path-item-actions {
  display: flex;
  gap: 4px;
}

.path-item-actions button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 0.85rem;
  border-radius: 4px;
}

.path-item-actions button:hover {
  background: var(--border);
  color: var(--text);
}

.path-segments {
  padding: 4px 4px 4px 20px;
  border-top: 1px solid var(--border);
}

.preview-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--sky);
  position: relative;
}

.preview-wheel-trap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior: none;
  scrollbar-width: none;
}

.preview-wheel-trap::-webkit-scrollbar {
  display: none;
}

.preview-wheel-trap-inner {
  display: flex;
  flex-direction: column;
  min-width: calc(100% + 2px);
  min-height: 100%;
  height: 100%;
}

.preview-wheel-trap-inner canvas#preview-canvas {
  flex: 1;
  min-height: 0;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.zoom-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  min-width: 44px;
  text-align: center;
}

.btn-icon {
  min-width: 28px;
  padding-left: 8px;
  padding-right: 8px;
  font-size: 0.95rem;
  line-height: 1;
}

.preview-toolbar-spacer {
  flex: 1;
  min-width: 8px;
}

.panel-edge-toggle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 15;
  width: 22px;
  height: 60px;
  padding: 0;
  border: 1px solid var(--border);
  background: rgba(26, 29, 39, 0.92);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
}

.panel-edge-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
}

.panel-edge-toggle--left {
  left: 0;
  border-radius: 0 8px 8px 0;
  border-left: none;
}

.panel-edge-toggle--right {
  right: 0;
  border-radius: 8px 0 0 8px;
  border-right: none;
}

#preview-canvas {
  flex: 1;
  width: 100%;
  cursor: grab;
  display: block;
  min-height: 0;
  overscroll-behavior: none;
  touch-action: none;
}

#preview-canvas:active {
  cursor: grabbing;
}

#preview-canvas.cursor-marker {
  cursor: ns-resize;
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 24px 12px;
}

.hidden {
  display: none !important;
}
