/* Global styles and theme definitions */
/* Define light and dark variables on the body so switching the theme is as easy as toggling a class */

body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Dark theme variables */
/*
 * Dark theme palette tuned for comfortable reading.
 * The background colours are slightly lighter than pure black to reduce
 * eye strain, inspired by the original MAX PAD design. Text colours are
 * softened to off‑white tones for improved contrast without harshness.
 */
body.dark {
  /* Dark theme palette inspired by the original MAX PAD design.  Colours
     are slightly lighter than pure black to reduce eye strain. */
  /*
   * Updated dark theme palette: the background colour is slightly
   * lighter (around #323232) to reduce eye strain and match the
   * original MAX PAD appearance.  Container and border colours are
   * harmonised to provide subtle contrast.  Text is a soft off‑white.
   */
  --bg-color: #323232;      /* overall page background */
  --container-bg: #2b2b2b;  /* container background for notes and header */
  --text-color: #e0e0e0;    /* main text colour */
  --border-color: #505050;  /* subtle border for separators */
  --primary-color: #4caf50; /* accent colour for active elements */
}

/* Light theme variables */
body.light {
  --bg-color: #f5f5f5;
  --container-bg: #ffffff;
  --text-color: #222222;
  --border-color: #cccccc;
  --primary-color: #0066cc;
}

body {
  background-color: var(--bg-color);
  color: var(--text-color);
}

/* Header styles */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background-color: var(--container-bg);
  border-bottom: 1px solid var(--border-color);
}

.app-title {
  font-size: 1.5rem;
  font-weight: 600;
}

.app-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-controls select,
  .app-controls button {
    background-color: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.3rem 0.6rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
    width: 2rem;
    height: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
  }

.tab-bar {
  display: flex;
  overflow-x: auto;
  background-color: var(--container-bg);
  border-bottom: 1px solid var(--border-color);
  height: 2.3rem;

  /* Hide horizontal scrollbars while allowing scroll via mouse/touch.  This
     improves aesthetics when many tabs overflow the available space. */
  -ms-overflow-style: none; /* IE and Edge */
  scrollbar-width: none;   /* Firefox */
}

/* Chrome, Safari and Opera */
.tab-bar::-webkit-scrollbar {
  display: none;
}

.tab {
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  border-right: 1px solid var(--border-color);
  white-space: nowrap;
  position: relative;
  transition: background-color 0.2s ease;
}

.tab.active {
  background-color: var(--bg-color);
  font-weight: 600;
}

.tab .close-btn {
  margin-left: 0.6rem;
  font-size: 0.9rem;
  line-height: 1;
}

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

.note-area {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.note-container {
  background-color: var(--container-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  height: calc(100% - 1rem);
}

.note-options {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.note-options select {
  background-color: var(--bg-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.editor-wrapper {
  position: relative;
  flex: 1;
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--bg-color);
}

.editor-wrapper pre.code-highlight,
.editor-wrapper textarea {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 1rem;
  box-sizing: border-box;
  overflow: auto;
  line-height: 1.5;
  font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
  font-size: 0.95rem;
}

.editor-wrapper pre.code-highlight {
  pointer-events: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  /* The highlight layer itself does not set a colour so that the
     token colours defined below can shine through. */
  color: inherit;
}

.editor-wrapper textarea {
  background: transparent;
  /* Default text colour is the current theme's text colour.  When
     colourful highlighting is enabled, JavaScript will override
     this colour to transparent. */
  color: var(--text-color);
  border: none;
  resize: none;
  outline: none;
  caret-color: var(--text-color);
}

/* Scrollbar styling for dark theme */
body.dark ::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

body.dark ::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 4px;
}

body.dark ::-webkit-scrollbar-track {
  background-color: var(--bg-color);
}

/* Scrollbar styling for light theme */
body.light ::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

body.light ::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 4px;
}

body.light ::-webkit-scrollbar-track {
  background-color: var(--container-bg);
}

/* Rename button inside tab */
.rename-btn {
  margin-left: 0.4rem;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
}
.rename-btn:hover {
  opacity: 1;
}

/* Language selection buttons */
.language-options {
  display: flex;
  gap: 0.4rem;
}

.language-options .language-btn {
  /*
   * Use the container background for inactive buttons so they are
   * visible against the darker page background.  The border
   * provides subtle delineation from the surrounding area.  Icons
   * inherit the current text colour.
   */
  background-color: var(--container-bg);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, color 0.2s ease;
  width: 2rem;
  height: 2rem;
}

.language-options .language-btn i {
  pointer-events: none;
}

.language-options .language-btn.active {
  background-color: var(--primary-color);
  color: #fff;
}

/*
 * CodeMirror overrides: ensure the editor adopts the same
 * colours and sizing as the surrounding textarea.  Without these
 * overrides, CodeMirror applies its own background and padding which
 * can cause misalignment or mismatched colours when switching between
 * themes.  The gutter (line numbers area) is also coloured to match.
 */
.editor-wrapper .CodeMirror {
  background-color: var(--bg-color) !important;
  color: var(--text-color) !important;
  height: 100%;
  padding: 1rem;
  box-sizing: border-box;
  font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
  font-size: 0.95rem;
  line-height: 1.5;
}
.editor-wrapper .CodeMirror-gutters {
  background-color: var(--bg-color) !important;
  border-right: 1px solid var(--border-color) !important;
}

/* Ensure the syntax highlight layer matches the editor background so plain text doesn't appear darker */
.editor-wrapper pre.code-highlight {
  background-color: transparent;
}

/* Colour definitions for tokens used by the simple highlighter.  These
   colours are inspired by popular dark themes and provide visual
   separation of keywords, strings, numbers and comments. */
.token.keyword { color: #c586c0; }
.token.number  { color: #b5cea8; }
.token.string  { color: #ce9178; }
.token.comment { color: #6a9955; }
.token.variable{ color: #9cdcfe; }