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

/* Ensure hidden attribute works even with display overrides */
[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
  background-color: #f5f5f5;
  color: #222;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Typography */
h1, h2, h3 {
  margin: 0 0 0.5rem;
  line-height: 1.3;
}

h1 {
  font-size: 1.5rem;
}

h2 {
  font-size: 1.25rem;
  color: #333;
  border-bottom: 2px solid #4a90a4;
  padding-bottom: 0.25rem;
  margin-top: 1.5rem;
}

h3 {
  font-size: 1rem;
  color: #555;
}

/* Layout */
.container {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
  flex: 1;
}

/* Header */
.header {
  background: linear-gradient(135deg, #2c3e50, #4a90a4);
  color: white;
  padding: 1rem;
  text-align: center;
}

.header-top {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  position: relative;
}

.header h1 {
  margin: 0;
}

.header-desc {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
  opacity: 0.9;
}

/* Language Toggle */
.lang-toggle {
  position: absolute;
  right: 0;
  display: flex;
  gap: 0;
  padding: 0;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 4px;
  background: transparent;
  overflow: hidden;
  cursor: pointer;
}

.lang-toggle span {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(255,255,255,0.6);
  transition: background-color 0.2s, color 0.2s;
}

.lang-toggle span.active {
  background: rgba(255,255,255,0.2);
  color: white;
}

.lang-toggle:hover span {
  color: rgba(255,255,255,0.8);
}

.lang-toggle:hover span.active {
  color: white;
}

/* Tab Bar */
.tab-bar {
  display: flex;
  gap: 0;
  background: #e0e0e0;
  border-radius: 8px 8px 0 0;
  overflow: hidden;
  margin-top: 1rem;
}

.tab-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  border: none;
  background: transparent;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
  color: #666;
}

.tab-btn:hover {
  background: #d0d0d0;
}

.tab-btn.active {
  background: white;
  color: #2c3e50;
}

/* Tab Content */
.tab-content {
  background: white;
  padding: 1rem;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  width: 100%;
  min-height: 5rem;
}

.tab-content[hidden] {
  display: none;
}

.tab-bar + .tab-content,
.tab-content + .tab-content[hidden] + .tab-content {
  margin-top: 0;
}

/* Scheme Selector */
.scheme-selector {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.scheme-selector label {
  font-weight: 600;
  flex-shrink: 0;
}

.scheme-selector select {
  flex: 1 1 auto;
  width: 0;
  min-width: 200px;
  padding: 0.5rem;
  font-size: 0.9rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: white;
}

.info-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: #4a90a4;
  color: white;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.2s;
}

.info-btn:hover {
  background: #3a7a94;
}

.scheme-note {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: #f0f7fa;
  border-left: 3px solid #4a90a4;
  font-size: 0.875rem;
  color: #555;
}

.scheme-name {
  font-weight: 600;
  color: #2c3e50;
}

/* Hebrew Keyboard */
.hebrew-keyboard {
  margin-top: 1rem;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
}

.keyboard-label {
  margin: 0 0 0.75rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: #555;
}

.hebrew-key-group {
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  background: white;
  border-radius: 6px;
  border: 1px solid #e8e8e8;
}

.hebrew-key-group:last-of-type {
  margin-bottom: 0;
}

.group-label {
  display: block;
  font-size: 0.75rem;
  color: #666;
  margin-bottom: 0.5rem;
  font-weight: 500;
  text-align: center;
}

.hebrew-keys {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.375rem;
  direction: rtl;
}

.hebrew-keys-4 {
  grid-template-columns: repeat(4, 1fr);
}

.hebrew-key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.25rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fafafa;
  font-size: 1.5rem;
  font-family: "SBL Hebrew", "Ezra SIL", "Times New Roman", serif;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
  min-height: 3.5rem;
}

.hebrew-key span {
  font-size: 0.65rem;
  color: #888;
  font-family: system-ui, sans-serif;
  margin-top: 0.125rem;
}

.hebrew-key:hover {
  background: #e8f4f8;
  border-color: #4a90a4;
}

.hebrew-key:active {
  background: #d4edda;
  transform: scale(0.95);
}

.keyboard-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: center;
}

/* Input Section */
.input-section {
  margin-top: 1.5rem;
  background: white;
  padding: 1rem;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.input-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.input-header label {
  font-weight: 600;
}

.input-header select {
  padding: 0.375rem 0.5rem;
  font-size: 0.875rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: white;
}

#input-text {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  font-family: monospace;
  border: 1px solid #ccc;
  border-radius: 4px;
  resize: vertical;
  min-height: 80px;
}

#input-text:focus {
  outline: none;
  border-color: #4a90a4;
  box-shadow: 0 0 0 2px rgba(74, 144, 164, 0.2);
}

/* Buttons */
.btn-primary {
  display: block;
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: white;
  background: #4a90a4;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-primary:hover {
  background: #3a7a94;
}

.btn-primary:active {
  background: #2a6a84;
}

.btn-secondary {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  color: #333;
  background: #e0e0e0;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-secondary:hover {
  background: #d0d0d0;
}

/* Warnings Section */
.warnings-section {
  margin-top: 1.5rem;
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 8px;
  padding: 1rem;
}

.warnings-section h2 {
  color: #856404;
  border-bottom-color: #ffc107;
  margin-top: 0;
}

.warnings-section ul {
  margin: 0;
  padding-left: 1.25rem;
}

.warnings-section li {
  color: #856404;
  margin-bottom: 0.25rem;
}

/* Results Section */
.results-section {
  margin-top: 1.5rem;
  background: white;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.results-section h2 {
  margin-top: 0;
}

/* Trace Steps */
.trace-step {
  margin-top: 1rem;
  padding: 1rem;
  background: #fafafa;
  border-radius: 4px;
  border: 1px solid #e0e0e0;
}

.trace-step h3 {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

/* Token Display */
.token-display {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  font-family: monospace;
  font-size: 1.1rem;
}

.token {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  min-width: 2rem;
  text-align: center;
}

.token.included {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.token.excluded {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
  text-decoration: line-through;
}

.token.normalized {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeeba;
}

.token-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.75rem;
  font-size: 0.8rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.token-sample {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border-radius: 2px;
}

.token-sample.included {
  background: #d4edda;
  border: 1px solid #c3e6cb;
}

.token-sample.excluded {
  background: #f8d7da;
  border: 1px solid #f5c6cb;
}

.token-sample.normalized {
  background: #fff3cd;
  border: 1px solid #ffeeba;
}

/* Mapping Display */
.mapping-display {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-family: monospace;
}

.mapping-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem;
  background: #e8f4f8;
  border-radius: 4px;
  min-width: 3rem;
}

.mapping-token {
  font-weight: 600;
  font-size: 1.1rem;
}

.mapping-arrow {
  color: #888;
  font-size: 0.8rem;
}

.mapping-value {
  color: #4a90a4;
  font-weight: 600;
}

.mapping-item.excluded {
  background: #f8d7da;
  opacity: 0.6;
}

.mapping-item.excluded .mapping-token {
  text-decoration: line-through;
}

.mapping-item.excluded .mapping-value {
  color: #721c24;
}

.mapping-item.normalized {
  background: #fff3cd;
}

.mapping-item.normalized .mapping-value {
  color: #856404;
}

/* Summation Display */
.summation-display {
  font-family: monospace;
  font-size: 1rem;
  padding: 0.75rem;
  background: #e8f4f8;
  border-radius: 4px;
  overflow-x: auto;
  white-space: nowrap;
}

.total-display {
  margin-top: 0.75rem;
  padding: 1rem;
  background: #4a90a4;
  color: white;
  border-radius: 4px;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
}

.excluded-list {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  color: #721c24;
}

.excluded-list:empty {
  display: none;
}

/* Reference Section */
.reference-section {
  margin-top: 1.5rem;
  background: white;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.reference-section h2 {
  margin-top: 0;
}

.reference-table-wrapper {
  overflow-x: auto;
}

.reference-table {
  width: 100%;
  border-collapse: collapse;
  font-family: monospace;
  font-size: 0.9rem;
}

.reference-table th,
.reference-table td {
  padding: 0.5rem;
  text-align: center;
  border: 1px solid #e0e0e0;
}

.reference-table th {
  background: #4a90a4;
  color: white;
  font-weight: 600;
}

.reference-table tbody tr:nth-child(even) {
  background: #f8f8f8;
}

.reference-table tbody tr:hover {
  background: #e8f4f8;
}

.reference-table .highlight {
  background: #fff3cd !important;
}

/* Footer */
.footer {
  background: #2c3e50;
  color: white;
  text-align: center;
  padding: 1rem;
  margin-top: 2rem;
}

.footer a {
  color: #7ec8e3;
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* Modal */
.info-modal {
  border: none;
  border-radius: 8px;
  padding: 0;
  max-width: 90%;
  width: 400px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.info-modal::backdrop {
  background: rgba(0,0,0,0.5);
}

.modal-content {
  padding: 1.5rem;
}

.modal-content h3 {
  margin-top: 0;
  color: #2c3e50;
}

#modal-body {
  margin: 1rem 0;
  line-height: 1.6;
}

#modal-body ul {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

#modal-body li {
  margin-bottom: 0.25rem;
}

#modal-close {
  display: block;
  width: 100%;
}

/* Basics Tab Content */
.basics-content {
  padding: 0.5rem 0;
}

.basics-content h3 {
  color: #2c3e50;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  font-size: 1.1rem;
  border-bottom: 1px solid #e0e0e0;
  padding-bottom: 0.25rem;
}

.basics-content h3:first-child {
  margin-top: 0;
}

.basics-content p {
  margin: 0 0 1rem;
  color: #555;
  line-height: 1.7;
}

.basics-steps {
  margin: 0.5rem 0 1rem;
  padding-left: 1.5rem;
}

.basics-steps li {
  margin-bottom: 0.5rem;
  color: #555;
}

.basics-schemes {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
}

.scheme-card {
  background: #f8f9fa;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1rem;
  border-left: 4px solid #4a90a4;
}

.scheme-card h4 {
  margin: 0 0 0.5rem;
  color: #2c3e50;
  font-size: 1rem;
}

.scheme-card p {
  margin: 0;
  font-size: 0.9rem;
  color: #666;
}

/* Tablet (600px+) */
@media (min-width: 600px) {
  h1 {
    font-size: 2rem;
  }

  .header-desc {
    font-size: 1rem;
  }

  .tab-btn {
    flex: none;
    padding: 0.75rem 2rem;
  }

  .btn-primary {
    width: auto;
    display: inline-block;
  }

  .reference-table {
    font-size: 1rem;
  }

  .total-display {
    font-size: 2rem;
  }

  .basics-schemes {
    grid-template-columns: repeat(3, 1fr);
  }

  .hebrew-keys {
    grid-template-columns: repeat(9, 1fr);
  }
}

/* Desktop (900px+) */
@media (min-width: 900px) {
  .container {
    padding: 1.5rem;
  }

  .header {
    padding: 1.5rem;
  }

  h1 {
    font-size: 2.5rem;
  }

  .input-section {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    align-items: start;
  }

  .input-header {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  #input-text {
    grid-column: 1;
    grid-row: 2;
  }

  #calculate-btn {
    grid-column: 2;
    grid-row: 2;
    margin-top: 0;
    height: 100%;
    min-height: 80px;
  }

  .hebrew-keyboard {
    grid-column: 1 / -1;
    grid-row: 3;
  }
}
