:root {
  /* Base theme colors */
  --bg: #0f172a;
  --panel: #111827;
  --line: #243244;
  --cell: #0e1a2b;
  --cell-active: #08d1b0;
  --text: #e5e7eb;
  --muted: #9aa7b8;
  --accent: #006f54;

  /* Interactive states */
  --cell-hover: #1c3455;
  --play-btn: #0552b7;
  --play-btn-hover: #0967d2;
  --playing: #f6ffc8;
  --accent-transparent: rgba(0, 111, 84, 0.2);

  /* Status indicators */
  --success: #52c41a;
  --warning: #faad14;
  --error: #f5222d;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.15);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.25);
}

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

/* Basic styles */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  background-color: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Header Styles */
.app-header {
  width: 100%;
  background: linear-gradient(135deg, var(--panel) 0%, var(--bg) 100%);
  padding: 30px 20px;
  margin: -20px -20px 30px -20px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  position: relative;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
}

.app-title {
  color: var(--text);
  font-weight: 700;
  font-size: clamp(2rem, 5vw, 3rem);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.app-subtitle {
  color: var(--muted);
  font-size: 1.1rem;
  margin: 0;
  font-weight: 400;
}

.help-button {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-weight: bold;
  font-size: 1.2rem;
}

.help-button:hover {
  background: var(--cell-active);
  transform: translateY(-50%) scale(1.05);
  box-shadow: var(--shadow);
}

main {
  width: 100%;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Controls Container */
.controls-container {
  background-color: var(--panel);
  padding: 15px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: fit-content;
  margin-bottom: 25px;
  flex-wrap: wrap;
  gap: 20px;
}

.playback-controls,
.grid-controls {
  display: flex;
  align-items: center;
  gap: 20px;
}

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

.control-button,
.control-select {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background-color: var(--panel);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
}

.control-button:hover,
.control-select:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-transparent);
}

/* Slider styling */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--cell-active);
  cursor: pointer;
  border: 2px solid var(--panel);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--cell-active);
  cursor: pointer;
  border: 2px solid var(--panel);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--accent);
  transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb:hover {
  background: var(--accent);
  transform: scale(1.1);
}

#play {
  background-color: var(--play-btn);
  color: var(--text);
  border-color: var(--play-btn);
  font-weight: 500;
}

#play:hover {
  background-color: var(--play-btn-hover);
  border-color: var(--play-btn-hover);
}

/* Grid Container */
.grid-container {
  background-color: var(--panel);
  padding: 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow-x: auto; /* Allow horizontal scrolling for the grid */
}

.grid-layout {
  display: flex;
}

/* Left Side: Note Labels */
.labels-left-side {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
}

.ruler-spacer {
  height: 32px; /* Match ruler height */
  border-bottom: 1px solid var(--line);
}

.row-labels {
  display: grid;
  /* Grid template rows are set dynamically in JS */
}

.row-label-text {
  width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--line);
}

/* Right Side: Grid and Ruler */
.grid-right-side {
  display: flex;
  flex-direction: column;
}

/* Ruler with Beat Numbers */
.ruler {
  display: grid;
  height: 32px;
  border-bottom: 1px solid var(--line);
  /* Grid template columns are set dynamically in JS */
}

.ruler-beat {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--muted);
}

/* Main Grid */
.grid-inner {
  display: grid;
  /* Grid template columns are set dynamically in JS */
}

/* Individual grid cells */
.cell {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  background-color: var(--cell);
  cursor: pointer;
  transition: background-color 0.1s ease;
}

.cell:hover {
  background-color: var(--cell-hover);
}

.cell.active {
  background-color: var(--cell-active);
}

/* Highlighting for the playing column */
.cell.playing-col,
.ruler-beat.playing-col {
  background-color: var(--playing);
}

/* Styling focus states for better accessibility while maintaining the theme */
button:focus,
input:focus,
select:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-transparent);
}

/* Grid Configuration Styling */
.grid-config {
  margin-top: -10px;
  margin-bottom: 15px;
}

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

.value-display {
  min-width: 40px;
  font-size: 13px;
  color: var(--muted);
}

input[type="number"] {
  width: 60px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background-color: var(--panel);
  color: var(--text);
  font-size: 14px;
}

.note-range-selector {
  display: flex;
  gap: 16px;
}

/* ===== NOTIFICATION SYSTEM ===== */
.notification-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.notification {
  background-color: var(--panel);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--accent);
  max-width: 300px;
  opacity: 1;
  transform: translateX(0);
  transition: all 0.2s ease-out;
  pointer-events: auto;
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
  position: relative;
}

.notification:hover {
  transform: translateX(-2px);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.notification--success {
  border-left-color: var(--success);
  background-color: rgba(82, 196, 26, 0.1);
}

.notification--error {
  border-left-color: var(--error);
  background-color: rgba(245, 34, 45, 0.1);
}

.notification--warning {
  border-left-color: var(--warning);
  background-color: rgba(250, 173, 20, 0.1);
}

.notification--info {
  border-left-color: var(--accent);
  background-color: rgba(0, 111, 84, 0.1);
}

/* Responsive adjustments for small screens */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  .app-header {
    padding: 20px 15px;
    margin: -10px -10px 20px -10px;
  }

  .app-title {
    font-size: clamp(1.8rem, 6vw, 2.5rem);
  }

  .app-subtitle {
    font-size: 1rem;
  }

  .controls-container {
    padding: 15px;
    flex-direction: column;
    align-items: stretch;
    gap: 15px;
  }

  .playback-controls,
  .grid-controls {
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
  }

  .control-group {
    flex-direction: column;
    text-align: center;
    gap: 4px;
  }

  .control-group label {
    font-size: 0.9rem;
    font-weight: 500;
  }

  input[type="range"] {
    width: 100px;
  }

  .note-range-selector {
    flex-direction: column;
    gap: 8px;
  }

  .config-group {
    flex-direction: column;
    text-align: center;
    gap: 6px;
  }

  /* Grid adjustments for mobile */
  .grid-container {
    padding: 15px;
    overflow-x: auto;
  }

  .cell,
  .ruler-beat,
  .row-label-text {
    width: 28px;
    height: 28px;
    font-size: 0.75rem;
  }

  .ruler-spacer {
    height: 28px;
  }

  /* Notification adjustments */
  .notification-container {
    left: 10px;
    right: 10px;
    top: 10px;
  }

  .notification {
    max-width: none;
    padding: 10px 14px;
    font-size: 0.9rem;
  }

  /* Help button adjustments */
  .help-button {
    position: static;
    transform: none;
    margin-top: 15px;
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  .help-button:hover {
    transform: scale(1.05);
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  .app-header {
    padding: 15px 10px;
  }

  .header-content {
    text-align: center;
  }

  .help-button {
    position: static;
    margin: 12px auto 0;
  }

  .controls-container {
    padding: 12px;
  }

  .control-button,
  .control-select {
    padding: 10px 14px;
    font-size: 0.9rem;
  }

  .cell,
  .ruler-beat,
  .row-label-text {
    width: 24px;
    height: 24px;
    font-size: 0.7rem;
  }

  .ruler-spacer {
    height: 24px;
  }

  .grid-container {
    padding: 10px;
  }

  input[type="range"] {
    width: 80px;
  }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .app-header {
    padding: 15px 20px;
  }

  .help-button {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    margin: 0;
  }

  .controls-container {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .playback-controls,
  .grid-controls {
    flex: 1;
    min-width: 200px;
  }
}

/* ===== HELP OVERLAY SYSTEM ===== */
.help-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.help-overlay[hidden] {
  display: none;
}

.help-content {
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  border: 1px solid var(--line);
}

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

.help-header h2 {
  margin: 0;
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 600;
}

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

.close-help-btn:hover {
  background: var(--cell-hover);
  color: var(--text);
}

.help-body {
  padding: 24px;
}

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

.help-section:last-child {
  margin-bottom: 0;
}

.help-section h3 {
  margin: 0 0 12px 0;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
}

.help-section p {
  margin: 0 0 16px 0;
  color: var(--muted);
  line-height: 1.5;
}

.help-section ul {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.6;
}

.help-section li {
  margin-bottom: 8px;
}

.help-section strong {
  color: var(--text);
  font-weight: 600;
}

@media (max-width: 600px) {
  .help-content {
    margin: 10px;
    max-height: 90vh;
  }

  .help-header {
    padding: 20px 20px 12px 20px;
  }

  .help-body {
    padding: 20px;
  }
}
