:root {
  --bg-dark: #0b1120;
  --bg-panel: #111827;
  --bg-elevated: #1e293b;
  --border-subtle: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-blue: #1D4ED8;
  --accent-sky: #38BDF8;
  --accent-gold: #FACC15;
  --accent-orange: #FF4D00;
  --toolbar-w: 68px;
  --topbar-h: 44px;
  --timeline-h: 132px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  touch-action: none;
}

/* Bố cục tối ưu màn hình ngang tỷ lệ 3:2 (Huawei MatePad Pro 12.2: 2800x1840) */
#app-shell {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Thanh công cụ dọc mảnh bên trái (tay trái) */
#left-toolbar {
  width: var(--toolbar-w);
  min-width: var(--toolbar-w);
  height: 100%;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 4px;
  gap: 4px;
  z-index: 20;
  overflow-y: auto;
}

.toolbar-brand {
  padding: 2px 0 4px;
}

.brand-badge {
  display: inline-block;
  background: linear-gradient(135deg, #1D4ED8, #0284c7);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  letter-spacing: 0.5px;
}

.tool-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  align-items: center;
}

.tool-bottom {
  margin-top: auto;
}

.tool-divider {
  width: 70%;
  height: 1px;
  background: var(--border-subtle);
  margin: 2px 0;
}

.tool-btn {
  width: 58px;
  min-height: 44px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  padding: 4px 2px;
  transition: all 0.12s ease;
}

.tool-btn span {
  font-size: 10px;
  font-weight: 600;
  line-height: 1.1;
  text-align: center;
}

.tool-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-main);
}

.tool-btn.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: var(--accent-sky);
  color: #ffffff;
}

.dot-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  color: #ffffff;
}

/* Vùng làm việc chính */
#workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
}

/* Thanh Top Bar mảnh */
#top-bar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 10px;
}

.drill-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.badge-code {
  background: #1e3a8a;
  color: #93c5fd;
  border: 1px solid #3b82f6;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  white-space: nowrap;
}

#drill-title {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-pill {
  font-size: 11px;
  color: #34d399;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

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

.action-btn {
  background: var(--bg-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.action-btn:hover {
  border-color: var(--accent-sky);
}

.action-btn.primary {
  background: var(--accent-blue);
  border-color: #3b82f6;
}

/* Vùng sân 7 chiếm >75% màn hình */
#pitch-viewport {
  flex: 1;
  position: relative;
  background: #06130c;
  overflow: hidden;
  touch-action: none; /* Bắt buộc để chống cuộn/zoom trình duyệt khi dùng bút & 2 ngón */
}

#konva-container {
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Banner pha chiến thuật nổi gọn trên sân */
#phase-banner {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.86);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 999px;
  padding: 5px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  max-width: 90%;
}

#phase-time {
  background: var(--accent-gold);
  color: #0f172a;
  font-weight: 800;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
}

#phase-desc {
  font-size: 12px;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Drawer ghi chú giáo án */
#coaching-drawer {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 330px;
  max-height: calc(100% - 20px);
  background: rgba(17, 24, 39, 0.95);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  z-index: 15;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

#coaching-drawer.hidden {
  display: none;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.drawer-header h3 {
  font-size: 13px;
  color: var(--accent-sky);
}

.drawer-header button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
}

.drawer-body {
  padding: 10px 12px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.5;
  color: #e2e8f0;
}

.drawer-body h4 {
  color: var(--accent-gold);
  margin-top: 8px;
  margin-bottom: 3px;
  font-size: 12px;
}

.drawer-body h4:first-child {
  margin-top: 0;
}

/* Thanh Multi-track Timeline cạnh dưới */
#timeline-panel {
  height: var(--timeline-h);
  min-height: var(--timeline-h);
  background: var(--bg-panel);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: 6px 12px;
  gap: 6px;
  z-index: 20;
}

.timeline-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 32px;
}

.playback-group, .speed-group, .keyframe-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ctrl-btn, .speed-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.ctrl-btn.play-btn {
  background: #15803d;
  border-color: #22c55e;
  min-width: 74px;
}

.ctrl-btn.play-btn.playing {
  background: #b45309;
  border-color: #f59e0b;
}

.ctrl-btn.active, .speed-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-sky);
  color: #fff;
}

.kf-btn {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

.scrubber-group {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mono-time {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--accent-sky);
  min-width: 38px;
  text-align: center;
}

#timeline-scrubber {
  flex: 1;
  accent-color: var(--accent-sky);
  height: 6px;
  cursor: pointer;
}

/* Vùng hiển thị Multi-track lanes */
#multitrack-view {
  flex: 1;
  background: #0f172a;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.track-row {
  display: flex;
  align-items: center;
  height: 16px;
  gap: 8px;
}

.track-label {
  width: 92px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 5px;
}

.track-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.track-bar {
  flex: 1;
  height: 10px;
  background: rgba(51, 65, 85, 0.45);
  border-radius: 4px;
  position: relative;
}

.track-playhead {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: #38BDF8;
  pointer-events: none;
}

.kf-diamond {
  position: absolute;
  top: 50%;
  width: 8px;
  height: 8px;
  background: #FACC15;
  border: 1px solid #0f172a;
  transform: translate(-50%, -50%) rotate(45deg);
  cursor: pointer;
}

.kf-diamond:hover {
  transform: translate(-50%, -50%) rotate(45deg) scale(1.3);
}
