:root {
  --font: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --ink: #0f172a;
  --ink-soft: #475569;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: rgba(148, 163, 184, 0.35);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 30px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 48px rgba(15, 23, 42, 0.1);
  --primary: #0d9488;
  --primary-deep: #0f766e;
  --primary-glow: rgba(13, 148, 136, 0.35);
  --secondary-fg: #334155;
  --secondary-border: #cbd5e1;
  --warn: #ea580c;
  --warn-deep: #c2410c;
  --muted: #64748b;
  --radius: 14px;
  --radius-sm: 10px;
  --ease: cubic-bezier(0.33, 1, 0.68, 1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 20px;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(45, 212, 191, 0.18), transparent 55%),
    radial-gradient(900px 500px at 95% 0%, rgba(251, 191, 36, 0.12), transparent 50%),
    radial-gradient(800px 400px at 50% 100%, rgba(96, 165, 250, 0.1), transparent 45%),
    linear-gradient(165deg, #f1f5f9 0%, #f8fafc 40%, #eef2ff 100%);
  background-attachment: fixed;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h2 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

h2::before {
  content: "";
  width: 4px;
  height: 1.1em;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--primary) 0%, #2dd4bf 100%);
  flex-shrink: 0;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.top-bar-title {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.top-bar-title h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  background: linear-gradient(120deg, var(--ink) 0%, var(--primary-deep) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.tab-group {
  display: inline-flex;
  padding: 4px;
  background: rgba(241, 245, 249, 0.9);
  border-radius: 999px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.top-actions label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
}

.top-actions input[type="number"] {
  width: 64px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--secondary-border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.top-actions input[type="number"]:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.2);
}

.panel {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.95);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.25s var(--ease);
}

.panel:hover {
  box-shadow: var(--shadow-lg);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.section-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-form {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.inline-form input,
.inline-form select {
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--secondary-border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  min-width: 140px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.inline-form input:focus-visible,
.inline-form select:focus-visible,
.inline-form label:focus-within input,
.inline-form label:focus-within select {
  outline: none;
}

.inline-form input:focus-visible,
.inline-form select:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.18);
}

.inline-form label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
}

.hint {
  color: var(--ink-soft);
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.55;
}

.courts-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap: 14px;
}

.court-card {
  border: 1px solid rgba(45, 212, 191, 0.35);
  background: linear-gradient(145deg, #ecfdf5 0%, #f0fdfa 45%, #ffffff 100%);
  border-radius: var(--radius-sm);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.22s var(--ease), box-shadow 0.22s var(--ease);
}

.court-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(13, 148, 136, 0.12);
}

.court-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.court-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-deep);
}

.court-header button {
  flex-shrink: 0;
}

.teams {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 8px;
}

.team {
  border-radius: var(--radius-sm);
  padding: 10px;
  min-height: 92px;
  transition: border-color 0.2s;
}

.team:first-of-type {
  background: linear-gradient(180deg, #eff6ff 0%, #ffffff 55%);
  border: 1px solid #bfdbfe;
}

.team:last-of-type {
  background: linear-gradient(180deg, #fdf2f8 0%, #ffffff 55%);
  border: 1px solid #fbcfe8;
}

.team h4 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}

.player-tag {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.player-tag-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.player-tag-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.player-tag-meta {
  font-size: 12px;
  color: var(--ink-soft);
}

.player-tag-bound {
  border-color: color-mix(in srgb, var(--binding-accent) 45%, white);
  background:
    linear-gradient(90deg, var(--binding-soft) 0%, rgba(255, 255, 255, 0.94) 72%);
  box-shadow:
    inset 4px 0 0 var(--binding-accent),
    0 2px 10px rgba(15, 23, 42, 0.04);
}

.player-tag:last-child {
  margin-bottom: 0;
}

.player-tag:hover {
  border-color: rgba(13, 148, 136, 0.35);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

.people-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.queue-plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.queue-group {
  border: 1px solid rgba(13, 148, 136, 0.2);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(240, 253, 250, 0.75) 0%, #ffffff 100%);
  padding: 12px;
  box-shadow: var(--shadow-sm);
}

.queue-group-title {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary-deep);
  letter-spacing: 0.03em;
}

.session-config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.session-config-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  transition: background 0.2s, border-color 0.2s;
}

.session-config-item:hover {
  background: #fff;
  border-color: rgba(13, 148, 136, 0.25);
}

.session-tools {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 10px;
  align-items: end;
}

.session-tools label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
}

.session-tools input,
.session-tools textarea {
  width: 100%;
  border: 1px solid var(--secondary-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.session-tools input:focus-visible,
.session-tools textarea:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

.session-tools textarea {
  min-height: 72px;
  resize: vertical;
}

.manual-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.binding-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: var(--binding-accent, var(--primary-deep));
  background: color-mix(in srgb, var(--binding-soft, rgba(13, 148, 136, 0.12)) 82%, white);
  border: 1px solid color-mix(in srgb, var(--binding-accent, var(--primary)) 40%, white);
  white-space: nowrap;
}

.binding-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.binding-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--binding-accent) 35%, white);
  background:
    linear-gradient(90deg, var(--binding-soft) 0%, rgba(255, 255, 255, 0.96) 80%);
  box-shadow: var(--shadow-sm);
}

.binding-item-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  cursor: pointer;
  border: none;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary) 0%, #2dd4bf 100%);
  box-shadow: 0 2px 8px var(--primary-glow), var(--shadow-sm);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), filter 0.2s;
}

button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--primary-glow), 0 2px 6px rgba(15, 23, 42, 0.08);
  filter: brightness(1.03);
}

button:not(:disabled):active {
  transform: translateY(0);
  filter: brightness(0.98);
}

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.45), 0 2px 8px var(--primary-glow);
}

button.secondary {
  color: var(--secondary-fg);
  background: linear-gradient(180deg, #ffffff 0%, #f1f5f9 100%);
  border: 1px solid var(--secondary-border);
  box-shadow: var(--shadow-sm);
}

button.secondary:hover:not(:disabled) {
  background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
  border-color: #94a3b8;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
}

button.secondary:focus-visible {
  box-shadow: 0 0 0 3px rgba(100, 116, 139, 0.35), var(--shadow-sm);
}

button.warn {
  background: linear-gradient(135deg, var(--warn) 0%, #fb923c 100%);
  box-shadow: 0 2px 12px rgba(234, 88, 12, 0.35), var(--shadow-sm);
}

button.warn:hover:not(:disabled) {
  box-shadow: 0 6px 22px rgba(234, 88, 12, 0.4), var(--shadow-sm);
}

button.warn:focus-visible {
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.45), 0 2px 12px rgba(234, 88, 12, 0.35);
}

button.muted {
  color: #fff;
  background: linear-gradient(135deg, #94a3b8 0%, #cbd5e1 100%);
  box-shadow: 0 2px 8px rgba(100, 116, 139, 0.25);
}

button.muted:hover:not(:disabled) {
  box-shadow: 0 6px 18px rgba(100, 116, 139, 0.3);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  filter: none;
  box-shadow: none;
}

button.tab-btn {
  border: none;
  background: transparent;
  color: var(--secondary-fg);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 999px;
  box-shadow: none;
  filter: none;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}

button.tab-btn:hover:not(:disabled) {
  transform: none;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.65);
  filter: none;
  box-shadow: none;
}

button.tab-btn.tab-active {
  color: #fff;
  background: linear-gradient(135deg, var(--primary) 0%, #14b8a6 100%);
  box-shadow: 0 4px 14px var(--primary-glow);
}

button.tab-btn.tab-active:hover:not(:disabled) {
  transform: none;
  color: #fff;
  background: linear-gradient(135deg, #14b8a6 0%, var(--primary) 100%);
  filter: brightness(1.03);
  box-shadow: 0 6px 18px var(--primary-glow);
}

button.tab-btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.35);
}

.tiny-btn {
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
}

.stats-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 10px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.stats-table th,
.stats-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  font-size: 14px;
}

.stats-table th {
  background: linear-gradient(180deg, var(--surface-2) 0%, #f1f5f9 100%);
  font-weight: 600;
  color: var(--ink-soft);
  font-size: 13px;
}

.stats-table tr:last-child td {
  border-bottom: none;
}

.stats-table tbody tr {
  background: var(--surface);
  transition: background 0.15s;
}

.stats-table tbody tr:hover {
  background: rgba(240, 253, 250, 0.65);
}

.manage-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 10px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.manage-table th,
.manage-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  font-size: 14px;
}

.manage-table th {
  background: linear-gradient(180deg, var(--surface-2) 0%, #f1f5f9 100%);
  font-weight: 600;
  color: var(--ink-soft);
  font-size: 13px;
}

.manage-table tr:last-child td {
  border-bottom: none;
}

.manage-table tbody tr {
  background: var(--surface);
  transition: background 0.15s;
}

.manage-table tbody tr:hover {
  background: rgba(239, 246, 255, 0.7);
}

.manage-table input,
.manage-table select {
  width: 100%;
  height: 34px;
  border: 1px solid var(--secondary-border);
  border-radius: 8px;
  padding: 0 8px;
  font: inherit;
}

.manage-table input:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.2);
}

.actions-cell {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hidden {
  display: none;
}

#queueContainer > p,
#restContainer > p,
#manageContainer > p {
  color: var(--ink-soft);
  font-size: 14px;
  padding: 12px;
  text-align: center;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--secondary-border);
}

.manual-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  user-select: none;
}

.manual-mode-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary-deep);
}

.manual-drop-surface {
  min-height: 56px;
  border-radius: var(--radius-sm);
  transition:
    background 0.2s,
    box-shadow 0.2s,
    border-color 0.2s;
}

.manual-drop-surface.drop-target-active {
  background: rgba(240, 253, 250, 0.85);
  box-shadow: inset 0 0 0 2px rgba(13, 148, 136, 0.45);
}

.queue-end-drop-strip {
  grid-column: 1 / -1;
  height: 10px;
  min-height: 10px;
  margin-top: 2px;
  border-radius: var(--radius-sm);
}

.queue-end-drop-strip.drop-target-active {
  background: rgba(240, 253, 250, 0.65);
  box-shadow: inset 0 0 0 2px rgba(13, 148, 136, 0.28);
}

.player-tag.drop-target-active {
  border-color: rgba(13, 148, 136, 0.55);
  box-shadow: inset 0 0 0 2px rgba(13, 148, 136, 0.12);
}

.court-slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 8px;
}

.court-team-slots {
  border-radius: var(--radius-sm);
  padding: 10px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.court-team-slots.team-a {
  background: linear-gradient(180deg, #eff6ff 0%, #ffffff 55%);
  border: 1px solid #bfdbfe;
}

.court-team-slots.team-b {
  background: linear-gradient(180deg, #fdf2f8 0%, #ffffff 55%);
  border: 1px solid #fbcfe8;
}

.court-team-slots h4 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}

.court-slot {
  min-height: 52px;
  border-radius: 10px;
  border: 1px dashed rgba(148, 163, 184, 0.75);
  background: rgba(255, 255, 255, 0.55);
  display: flex;
  align-items: center;
  padding: 4px;
  transition:
    border-color 0.2s,
    background 0.2s,
    box-shadow 0.2s;
}

.court-slot.drop-target-active {
  border-color: rgba(13, 148, 136, 0.75);
  background: rgba(240, 253, 250, 0.75);
  box-shadow: inset 0 0 0 2px rgba(13, 148, 136, 0.25);
}

.court-slot .player-tag {
  width: 100%;
  margin-bottom: 0;
}

.player-tag[draggable="true"] {
  cursor: grab;
}

.player-tag[draggable="true"]:active {
  cursor: grabbing;
}

.player-tag.dragging-source {
  opacity: 0.45;
}

body.manual-mode-on .panel {
  box-shadow: 0 8px 28px rgba(13, 148, 136, 0.08);
}

@media (max-width: 768px) {
  body {
    padding: 12px;
  }

  .top-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .courts-grid {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }

  .session-tools {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .tab-group {
    width: 100%;
    justify-content: center;
  }
}

.line-settings-form {
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.line-status-text.line-status-ok {
  color: var(--primary-deep);
}

.line-status-text.line-status-error {
  color: var(--warn-deep);
}
