:root {
  --bg: #0d1117;
  --bg-panel: #161b22;
  --bg-elevated: #1c2330;
  --border: #30363d;
  --border-soft: #21262d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #f0883e;
  --accent-dim: #9e4c1a;
  --primary: #238636;
  --primary-hover: #2ea043;
  --danger: #f85149;
  --grid: #21262d;
  --hole: #58a6ff;
  --selection: #ffd700;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Code", "Consolas", "SF Mono", monospace;
  --radius: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: linear-gradient(180deg, #1a2332 0%, var(--bg-panel) 100%);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(145deg, #f0a060 0%, var(--accent) 45%, #9e4c1a 100%);
  color: #1a1008;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(240, 136, 62, 0.35), 0 4px 12px rgba(240, 136, 62, 0.28);
}

.brand-wolf {
  width: 34px;
  height: 34px;
  display: block;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0.1rem 0 0;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 6px;
  padding: 0.45rem 0.85rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  background: #252d3a;
  border-color: #484f58;
}

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

.btn-primary {
  background: var(--primary);
  border-color: rgba(46, 160, 67, 0.6);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-ghost {
  background: transparent;
}

.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  min-width: 2rem;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.sidebar,
.table-panel {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  min-height: 0;
}

.table-panel {
  border-right: none;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.panel {
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border-soft);
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 650;
}

/* Drop zone */
.drop-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 0.85rem;
  text-align: center;
  background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(240, 136, 62, 0.08);
}

.drop-zone p {
  margin: 0.25rem 0;
}

.drop-icon {
  font-size: 1.4rem;
  opacity: 0.7;
  margin-bottom: 0.35rem;
}

.muted {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.hint {
  margin-top: 0.65rem !important;
  font-size: 0.72rem;
  color: var(--text-muted);
}

code {
  font-family: var(--mono);
  font-size: 0.78em;
  background: var(--bg-elevated);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  border: 1px solid var(--border-soft);
}

.file-info {
  margin-top: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border-soft);
  font-size: 0.8rem;
}

.file-info.hidden,
.hidden {
  display: none !important;
}

.file-info strong {
  color: var(--accent);
}

/* Stats */
.stats {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem 0.75rem;
}

.stats > div {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
}

.stats dt {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}

.stats dd {
  margin: 0.15rem 0 0;
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 550;
}

/* Toggles */
.toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.75rem 0 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.num-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.45rem 0.55rem;
  font: inherit;
  font-family: var(--mono);
  font-size: 0.85rem;
}

.num-input:focus {
  outline: none;
  border-color: var(--accent);
}

.num-input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.num-input-readonly,
.num-input-readonly:disabled {
  opacity: 1;
  cursor: default;
  color: var(--accent);
  font-weight: 650;
  border-color: rgba(240, 136, 62, 0.45);
  background: rgba(240, 136, 62, 0.08);
}

select.num-input {
  cursor: pointer;
  font-family: var(--font);
}

.depth-help {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  line-height: 1.4;
}

.depth-formula {
  margin: 0.65rem 0 0;
  font-size: 0.75rem;
  font-family: var(--mono);
  padding: 0.45rem 0.55rem;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border-soft);
}

.depth-formula.warn {
  color: var(--danger);
  border-color: rgba(248, 81, 73, 0.35);
}

.depth-formula.ok {
  color: #3fb950;
}

/* Legend */
.legend {
  margin-top: 0.85rem;
}

.legend-bar {
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    #3b82f6 0%,
    #22c55e 35%,
    #eab308 65%,
    #ef4444 100%
  );
  border: 1px solid var(--border);
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.legend-caption {
  margin: 0.25rem 0 0;
  text-align: center;
}

.selected-hole {
  font-size: 0.85rem;
  line-height: 1.55;
}

.selected-hole .hole-id {
  font-weight: 700;
  color: var(--selection);
  font-size: 1rem;
}

.selected-hole .kv {
  font-family: var(--mono);
  font-size: 0.8rem;
}

/* Viewport */
.viewport-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #0a0e14;
}

.viewport-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.toolbar-btns {
  display: flex;
  gap: 0.35rem;
}

.canvas-container {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  cursor: crosshair;
}

#blastCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(240, 136, 62, 0.06) 0%, transparent 55%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 39px,
      rgba(48, 54, 61, 0.35) 39px,
      rgba(48, 54, 61, 0.35) 40px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 39px,
      rgba(48, 54, 61, 0.35) 39px,
      rgba(48, 54, 61, 0.35) 40px
    );
}

.empty-state h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
  font-weight: 600;
}

.empty-state p {
  margin: 0.3rem 0;
  max-width: 28rem;
  color: var(--text-muted);
}

.coord-bar {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0.75rem;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Tooltip */
.tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  background: rgba(22, 27, 34, 0.95);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  font-size: 0.78rem;
  box-shadow: var(--shadow);
  max-width: 200px;
  white-space: nowrap;
}

.tooltip strong {
  color: var(--selection);
}

/* Table */
.table-header {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.85rem 1rem 0.65rem;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}

.table-header h2 {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 650;
}

.table-header input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.4rem 0.55rem;
  font: inherit;
  font-size: 0.8rem;
}

.table-header input:focus {
  outline: none;
  border-color: var(--accent);
}

.table-header input:disabled {
  opacity: 0.5;
}

.table-scroll {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

th {
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  text-align: left;
  padding: 0.45rem 0.65rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  z-index: 1;
}

td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border-soft);
  font-family: var(--mono);
  font-size: 0.7rem;
  white-space: nowrap;
}

tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

tbody tr:hover {
  background: rgba(88, 166, 255, 0.08);
}

tbody tr.selected {
  background: rgba(255, 215, 0, 0.12);
}

tbody tr.selected td:first-child {
  color: var(--selection);
  font-weight: 700;
}

.empty-row td {
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font);
  padding: 1.5rem;
}

/* Responsive */
@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 260px 1fr;
  }

  .table-panel {
    display: none;
  }
}

@media (max-width: 720px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .brand .subtitle {
    display: none;
  }

  .header {
    flex-wrap: wrap;
  }
}
