/**
 * Copyright 2026 by Kilian Q. Weinberger
 * Version: 0.1.0
 * License: MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/* CSS Variables */
:root {
  /* Primary colors */
  --primary-bg: #f8f9fa;
  --primary-text: #212529;
  --accent: #0066cc;
  --accent-hover: #0052a3;

  /* Token colors (by length) */
  --token-char: #e9ecef;
  --token-2gram: #cfe2ff;
  --token-3gram: #9ec5fe;
  --token-4plus: #6ea8fe;

  /* Highlight colors */
  --highlight-new: #fff3cd;
  --highlight-border: #ffca2c;

  /* UI elements */
  --panel-bg: #ffffff;
  --panel-border: #dee2e6;
  --button-disabled: #6c757d;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--primary-bg);
  color: var(--primary-text);
  line-height: 1.6;
  padding: 20px;
}

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 30px;
}

h1 {
  font-size: 2rem;
  margin-bottom: 10px;
  color: var(--primary-text);
}

.subtitle {
  color: #6c757d;
  font-size: 1.1rem;
}

.algorithm-note {
  color: #0066cc;
  font-size: 0.95rem;
  font-style: italic;
  margin-top: 8px;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

.algorithm-toggle {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 15px;
  padding: 15px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.toggle-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 10px 20px;
  border-radius: 6px;
  transition: all 0.3s ease;
  background: white;
  border: 2px solid #dee2e6;
}

.toggle-label:hover {
  border-color: var(--accent);
  background: #f8f9fa;
}

.toggle-label input[type="radio"] {
  margin-right: 8px;
  cursor: pointer;
  width: 18px;
  height: 18px;
}

.toggle-label input[type="radio"]:checked + .toggle-option {
  color: var(--accent);
  font-weight: 700;
}

.toggle-label:has(input[type="radio"]:checked) {
  border-color: var(--accent);
  background: #e7f3ff;
}

.toggle-option {
  font-size: 1rem;
}

.keyboard-shortcuts {
  margin-top: 12px;
  font-size: 0.9rem;
  color: #6c757d;
  font-style: italic;
}

h2 {
  font-size: 1.5rem;
  margin-bottom: 15px;
  color: var(--primary-text);
}

.token-count {
  font-size: 1.2rem;
  color: #6c757d;
  font-weight: 400;
}

/* Panels */
.panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Input Panel */
.input-panel {
  background: var(--panel-bg);
}

.input-text {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--panel-border);
  border-radius: 6px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
  font-size: 1rem;
  line-height: 1.5;
  resize: vertical;
  margin-bottom: 12px;
  transition: border-color 0.3s ease;
}

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

#btn-run-bpe {
  background-color: var(--accent);
  color: white;
  padding: 10px 30px;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#btn-run-bpe:hover {
  background-color: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#btn-run-bpe:active {
  transform: translateY(0);
}

.example-selector {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 15px;
}

.example-selector label {
  font-weight: 600;
  white-space: nowrap;
}

.example-select {
  padding: 8px 12px;
  border: 2px solid var(--panel-border);
  border-radius: 6px;
  font-size: 1rem;
  background-color: white;
  cursor: pointer;
  transition: border-color 0.3s ease;
  min-width: 200px;
}

.example-select:focus {
  outline: none;
  border-color: var(--accent);
}

.or-text {
  color: #6c757d;
  font-style: italic;
}

/* Test Panel */
.test-panel {
  background: #f8f9fa;
  border: 2px solid var(--accent);
}

.test-description {
  color: #6c757d;
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.test-text {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--panel-border);
  border-radius: 6px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
  font-size: 1rem;
  line-height: 1.5;
  resize: vertical;
  margin-bottom: 12px;
  transition: border-color 0.3s ease;
}

.test-text:focus {
  outline: none;
  border-color: var(--accent);
}

.test-result-container {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 2px solid var(--panel-border);
}

.test-result-container h3 {
  font-size: 1.2rem;
  margin-bottom: 12px;
  color: var(--primary-text);
}

.test-result {
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
  font-size: 1.1rem;
  line-height: 2;
  padding: 15px;
  background-color: white;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  min-height: 60px;
}

/* Controls Panel */
.controls-panel {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 15px;
  justify-content: center;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  background-color: white;
  color: #667eea;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn:disabled {
  background-color: var(--button-disabled);
  color: #adb5bd;
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-skip {
  background-color: rgba(255, 255, 255, 0.9);
  font-weight: 700;
}

.btn-finish {
  background-color: #28a745;
  color: white;
  font-weight: 700;
}

.btn-finish:hover:not(:disabled) {
  background-color: #218838;
}

.step-counter {
  font-size: 1.1rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.2);
  padding: 8px 15px;
  border-radius: 6px;
}

/* Tokenized Text Display */
.tokenized-text {
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
  font-size: 1.1rem;
  line-height: 2;
  padding: 10px;
  min-height: 150px;
}

.token {
  display: inline-block;
  padding: 4px 8px;
  margin: 2px;
  border-radius: 6px;
  border: 2px solid transparent;
  transition: all 0.3s ease;
  white-space: pre;
}

.token-length-1 {
  background-color: var(--token-char);
  color: var(--primary-text);
}

.token-length-2 {
  background-color: var(--token-2gram);
  color: var(--primary-text);
}

.token-length-3 {
  background-color: var(--token-3gram);
  color: var(--primary-text);
}

.token-length-4,
.token-length-5,
.token-length-6,
.token-length-7,
.token-length-8,
.token-length-9,
.token-length-10 {
  background-color: var(--token-4plus);
  color: white;
}

.token.new {
  background-color: var(--highlight-new);
  border-color: var(--highlight-border);
  animation: highlight 0.6s ease;
  color: var(--primary-text);
}

.token.space {
  background-color: #f8f9fa;
  border: 1px dashed #adb5bd;
}

.token.newline {
  display: block;
  height: 0;
  padding: 0;
  margin: 0;
  border: none;
}

@keyframes highlight {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Step Details */
.step-details {
  min-height: 80px;
}

.step-details p {
  margin-bottom: 10px;
  color: #6c757d;
  font-style: italic;
}

.merge-list {
  list-style: none;
}

.merge-item {
  padding: 10px;
  margin-bottom: 8px;
  background-color: #f8f9fa;
  border-left: 4px solid var(--accent);
  border-radius: 4px;
}

.merge-item code {
  background-color: #e9ecef;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: monospace;
  font-weight: 600;
}

.frequency {
  color: #6c757d;
  font-size: 0.9rem;
  margin-left: 10px;
}

/* Vocabulary */
.vocab-stats {
  margin-bottom: 15px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #6c757d;
}

.vocabulary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
  padding: 10px;
  background-color: #f8f9fa;
  border-radius: 6px;
}

.vocab-token {
  display: inline-block;
  padding: 4px 8px;
  background-color: #e9ecef;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9rem;
  border: 1px solid #dee2e6;
  transition: all 0.2s ease;
}

.vocab-token:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.vocab-token.new {
  background-color: var(--highlight-new);
  border-color: var(--highlight-border);
  font-weight: 600;
}

/* Next Pairs */
.next-pairs {
  min-height: 80px;
}

.next-pairs p {
  color: #6c757d;
  font-style: italic;
  margin-bottom: 10px;
}

.pair-list {
  list-style: none;
}

.pair-item {
  padding: 8px 12px;
  margin-bottom: 6px;
  background-color: #f8f9fa;
  border-radius: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pair-item code {
  background-color: #e9ecef;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: monospace;
  font-weight: 600;
}

.pair-count {
  color: #6c757d;
  font-size: 0.9rem;
}

.scoring-equation {
  background-color: #e7f3ff;
  border-left: 4px solid var(--accent);
  padding: 10px 15px;
  margin: 10px 0;
  border-radius: 4px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
  font-size: 0.95rem;
}

.scoring-equation strong {
  color: var(--accent);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Responsive Design */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  .container {
    padding: 0;
  }

  h1 {
    font-size: 1.5rem;
  }

  .subtitle {
    font-size: 1rem;
  }

  .panel {
    padding: 15px;
  }

  .controls {
    flex-direction: column;
    gap: 10px;
  }

  .btn {
    width: 100%;
  }

  .example-selector {
    width: 100%;
    justify-content: center;
  }

  .example-select {
    flex: 1;
    max-width: 200px;
  }

  .tokenized-text {
    font-size: 0.9rem;
  }

  .token {
    padding: 3px 6px;
    margin: 1px;
  }
}

/* Scrollbar Styling */
.vocabulary::-webkit-scrollbar {
  width: 8px;
}

.vocabulary::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 6px;
}

.vocabulary::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 6px;
}

.vocabulary::-webkit-scrollbar-thumb:hover {
  background: #555;
}
