/* Sanskrit Multi-Tier Analysis Tool Styles */

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.header {
    text-align: center;
    margin-bottom: 30px;
}

.header h1 {
    color: #4a5568;
    font-size: 2.5em;
    margin-bottom: 10px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header p {
    color: #718096;
    font-size: 1.1em;
}

.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    font-size: 14px;
    background: #e2e8f0;
    color: #4a5568;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.btn-secondary {
    background: #e2e8f0;
    color: #4a5568;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.workspace {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

/* Compact tier layout with single-letter labels and tooltips */
.tier {
    display: flex;
    align-items: stretch;
    margin-bottom: 4px; /* Reduced from previous spacing */
    background: white;
    border-radius: 6px; /* Reduced from 15px */
    box-shadow: 0 2px 6px rgba(0,0,0,0.08); /* Reduced shadow */
    border-left: 3px solid; /* Reduced from 4px */
    padding: 8px; /* Reduced from 20px */
    transition: border-left-width 0.2s ease, box-shadow 0.2s ease; /* Smooth animations */
}

/* Tier label - compact single letter */
.tier-label {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    font-weight: bold;
    font-size: 16px;
    color: white;
    border-radius: 4px;
    margin-right: 12px;
    cursor: help;
    position: relative;
    flex-shrink: 0;
}

.tier-i { display: none; } /* only show it if its preference is modified to show it */


  /* Tier label colors - rainbow ordered */
  .tier-i .tier-label { background: #ff0000; color: black; } /* actual Red */
  .tier-s .tier-label { background: #ef4444; color: white; } /* orange-Red */
  .tier-r .tier-label { background: #ff7f00; color: white; } /* Orange */
  .tier-b .tier-label { background: #fbbf24; color: #1f2937; } /* Yellow */
  .tier-f .tier-label { background: #fbec50; color: black; } /* Green */
  .tier-e .tier-label { background: #22c55e; color: #1f2937; } /* Cyan */
  .tier-p .tier-label { background: #22d3ee; color: white; } /* Blue */
  .tier-t .tier-label { background: #6366f1; color: white; } /* Indigo */
  .tier-c .tier-label { background: #a855f7; color: white; } /* Violet */

  Then add hover states after line 126 (or wherever you put the above):

  /* Tier label hover states */
  .tier-s .tier-label:hover { background: #dc2626; }
  .tier-r .tier-label:hover { background: #e67300; }
  .tier-b .tier-label:hover { background: #f59e0b; }
  .tier-f .tier-label:hover { background: #16a34a; }
  .tier-e .tier-label:hover { background: #06b6d4; }
  .tier-p .tier-label:hover { background: #2563eb; }
  .tier-t .tier-label:hover { background: #4f46e5; }
  .tier-c .tier-label:hover { background: #9333ea; }

/* Tooltip styling */
.tier-label::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 0;
    transform: translateX(0);
    max-width: 400px;
    width: max-content;
    background: #2d3748;
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: normal;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 1000;
    pointer-events: none;
}

.tier-label::after {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 16px;
    border: 4px solid transparent;
    border-top-color: #2d3748;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.tier-label:hover::before,
.tier-label:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Content area - flexible */
.tier-content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Convert buttons - more compact */
.tier-controls {
    display: flex;
    gap: 4px;
    margin-bottom: 6px;
    justify-content: flex-end;
}

.tier-controls button {
    font-size: 11px;
    padding: 4px 8px;
    border: none;
    border-radius: 3px;
    background: #e2e8f0;
    color: #4a5568;
    cursor: pointer;
    transition: all 0.15s ease;
}

/* Rainbow-ordered tier colors: V(Red) R(Orange) B(Yellow) F(Green) E(Cyan) P(Blue) T(Indigo) C(Violet) */
  button[data-convert="s-to-r"] { background: #ff7f00; /* R tier - Orange */  color: white;  }
  button[data-convert="r-to-b"] { background: #fbbf24; /* B tier - Yellow */  color: #1f2937; }
  button[data-convert="b-to-f"] { background: #fbec50; /* F tier - Yellow-Green */ color: black; }  /* CHANGE */
  button[data-convert="b-to-e"],
  button[data-convert="f-to-e"] { background: #22c55e; /* E tier - Green */   color: #1f2937; }  /* CHANGE */
  button[data-convert="e-to-p"] { background: #22d3ee; /* P tier - Cyan */    color: #1f2937; }  /* CHANGE */
  button[data-convert="p-to-t"] { background: #6366f1; /* T tier - Indigo */  color: white;  }
  button[data-convert="t-to-c"] { background: #a855f7; /* C tier - Violet */  color: white;  }
  button[data-convert="b-to-i"] { background: #ff0000; /* I tier - Red */     color: black; }    /* ADD */

  /* Hover states - slightly darker */
  button[data-convert="s-to-r"]:hover { background: #e67300; /* Darker orange */  }
  button[data-convert="r-to-b"]:hover { background: #f59e0b; /* Darker yellow */  }
  button[data-convert="b-to-f"]:hover { background: #e6d847; /* Darker yellow-green */ }  /* CHANGE */
  button[data-convert="b-to-e"]:hover,
  button[data-convert="f-to-e"]:hover { background: #16a34a; /* Darker green */   }  /* CHANGE */
  button[data-convert="e-to-p"]:hover { background: #06b6d4; /* Darker cyan */    }  /* CHANGE */
  button[data-convert="p-to-t"]:hover { background: #4f46e5; /* Darker indigo */  }
  button[data-convert="t-to-c"]:hover { background: #9333ea; /* Darker violet */  }
  button[data-convert="b-to-i"]:hover { background: #cc0000; /* Darker red */     }  /* ADD */
  

.tier-controls button:hover {
    background: #cbd5e0;
    transform: translateY(-1px);
}

/* Auto-resize textarea styling */
.tier-content {
    width: 100%;
    min-height: 2.2em;
    height: 2.2em;
    max-height: 8em; /* Limit to ~4 lines max */
    resize: none;
    overflow: hidden;
    font-family: 'Noto Sans Devanagari', 'Noto Sans', 'Noto Serif', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    padding: 6px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    background: white;
    box-sizing: border-box;
    transition: height 0.2s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Show scrollbar when content exceeds max height */
.tier-content.has-overflow {
    overflow-y: auto;
    resize: vertical;
}

.tier-content:focus {
    outline: none;
    border-color: #4299e1;
    box-shadow: 0 0 0 2px rgba(66, 153, 225, 0.1);
}

.tier-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.tier-title {
    font-weight: 700;
    font-size: 1.1em;
    color: #2d3748;
}

.tier-controls .btn {
    padding: 5px 10px;
    font-size: 12px;
}

/* Styling for expanded tiers */
.tier-expanded {
    border-left-width: 4px; /* Slightly thicker border when expanded */
    box-shadow: 0 3px 10px rgba(0,0,0,0.12); /* Deeper shadow */
}

.tier-expanded .tier-label {
    align-self: flex-start; /* Align to top when content is tall */
}


/* Devanagari specific styling */
#tier-s {
    font-family: 'Noto Sans Devanagari', 'Mangal', serif;
    font-size: 18px;
}

/* Dictionary Suggestions panel */
.dictionary-suggestions-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border: 2px solid #333;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 1000;
    max-width: 500px;
    max-height: 400px;
    overflow-y: auto;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    border-bottom: 1px solid #ccc;
    padding-bottom: 10px;
}

.panel-header h4 {
    margin: 0;
    flex: 1; /* Take available space */
}

.close-btn {
    margin-left: 10px; /* Space from title */
    flex-shrink: 0; /* Don't shrink */
    background: #ff4444;
    color: white;
    border: none;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    cursor: pointer;
}

.suggestion-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid #eee;
}

.add-word-btn {
    display: none; /* initial value */
}

.tier-b .add-word-btn { background: #fbbf24; color: black; }
.tier-f .add-word-btn { background: #fbec50; color: black; }

.add-btn, .skip-btn, .add-current-btn, .add-word-btn {
    padding: 8px 16px;
    margin: 0 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    min-width: 30px;
    max-width: none;
    text-align: center;
}

.add-btn { background: #4CAF50; color: white; }
.skip-btn { background: #ff9800; color: white; }
.add-current-btn { background: #2196F3; color: white; }

.convert-btn[data-convert="hk-to-deva"] { background: #ef4444; color: white; }

.current-translation {
    margin: 15px 0;
    line-height: 1.8;
}

.current-translation div {
    margin: 8px 0;
}


/* Preferences Panel */
.preferences-panel {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 20px;
    overflow: hidden;
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    box-shadow: -5px 0 20px rgba(0, 0, 0, 0.3);
    padding: 20px;
    overflow-y: auto;
    transition: right 0.3s ease;
    z-index: 1000;
}

.preferences-panel.open {
    right: 0;
}

.preferences-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #e2e8f0;
    border-bottom: 1px solid #d1d5db;
    cursor: pointer;
}

.preferences-header h3 {
    margin: 0;
    font-size: 16px;
    color: #374151;
}

.preference-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-weight: 500;
    color: #374151;
}

.preference-description {
    font-size: 12px;
    color: #6b7280;
    margin-top: 6px;
    margin-left: 24px;
    line-height: 1.4;
}

.preferences-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
}

.preferences-overlay.open {
    opacity: 1;
    visibility: visible;
}

.pref-section {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e2e8f0;
}

.pref-section:last-child {
    border-bottom: none;
}

.pref-section h4 {
    color: #2d3748;
    margin-bottom: 15px;
    font-size: 1.1em;
}

.preferences-toggle {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.preferences-toggle:hover {
    background: rgba(0,0,0,0.1);
}


.preferences-content {
    padding: 16px;
    display: none; /* Initially collapsed */
}

.preferences-content.expanded {
    display: block;
}

.pref-item {
    margin-bottom: 15px;
}

.pref-item label {
    display: block;
    margin-bottom: 5px;
    color: #4a5568;
    font-weight: 500;
}

.pref-item select,
.pref-item input[type="number"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
}

.pref-item input[type="checkbox"] {
    margin-right: 8px;
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    cursor: pointer;
}

.format-indicator {
    background: #4299e1;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    margin-left: 5px;
}

.status-bar {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.9);
    padding: 10px 15px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    font-size: 12px;
    color: #4a5568;
}


/* Morphology Controls */
.morphology-controls {
    margin: 10px 0;
    padding: 10px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 10px;
    border-left: 4px solid #38b2ac;
}

.morph-button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.morph-button-group .btn {
    font-size: 12px;
    padding: 8px 12px;
}

/* Dictionary Management Modal */
.dictionary-manager-modal,
.dictionary-selection-modal,
.morphology-tools-modal,
.break-insertion-modal,
.validation-results-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    position: relative;
}

.modal-content h3 {
    color: #2d3748;
    margin-bottom: 20px;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 10px;
}


.modal-content button {
    padding: 10px 20px;
    font-size: 14px;
    min-width: 80px;
}

/* Dictionary Interface */
.dict-stats {
    background: #f7fafc;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.dict-stats p {
    margin: 5px 0;
    font-weight: 500;
    color: #4a5568;
}

.dict-search {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.dict-search input {
    flex: 1;
    min-width: 200px;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
}

.dict-entries {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px;
}

.dict-entry {
    padding: 10px;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dict-entry:last-child {
    border-bottom: none;
}

.dict-entry strong {
    color: #2d3748;
    margin-right: 8px;
}

.dict-entry small {
    color: #718096;
    margin-left: 8px;
}

/* Online Dictionary Results */
.online-results {
    background: #f0fff4;
    border: 1px solid #9ae6b4;
    border-radius: 8px;
    padding: 15px;
    margin: 15px 0;
}

.entry-option {
    margin: 8px 0;
    padding: 5px;
    border-radius: 4px;
}

.entry-option:hover {
    background: #e6fffa;
}

.entry-option input {
    margin-right: 8px;
}

.custom-entry {
    margin: 15px 0;
}

.custom-entry textarea {
    width: 100%;
    min-height: 80px;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    resize: vertical;
    font-family: inherit;
}

/* Morphology Tools Interface */
.morphology-tools-modal .modal-content {
    max-width: 800px;
    width: 90%;
}

.tool-section {
    margin: 20px 0;
    padding: 15px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fafafa;
}

.tool-section h4 {
    color: #2d3748;
    margin-bottom: 15px;
    font-size: 1.1em;
}

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

.tool-controls input {
    flex: 1;
    min-width: 200px;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

.tool-controls button {
    padding: 10px 20px;
    font-size: 14px;
    min-width: 80px;
}

.tool-controls button:hover {
    background: #3182ce;
}

.results-area {
    min-height: 60px;
    padding: 10px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
}

.results-area .error {
    color: #e53e3e;
    font-style: italic;
}

/* Analysis Results */
.analysis-result,
.breakdown-result {
    padding: 10px;
    background: #f7fafc;
    border-radius: 6px;
    margin: 10px 0;
}

.suggestions {
    margin-top: 10px;
}

.suggestion {
    display: inline-block;
    background: #bee3f8;
    color: #2b6cb0;
    padding: 2px 8px;
    border-radius: 4px;
    margin: 2px;
    font-size: 12px;
    cursor: pointer;
}

.suggestion:hover {
    background: #90cdf4;
}

.components {
    margin-top: 10px;
}

.component {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 5px 0;
    border-bottom: 1px solid #e2e8f0;
}

.component:last-child {
    border-bottom: none;
}

.component .form {
    font-weight: bold;
    color: #2d3748;
    min-width: 80px;
}

.component .type {
    background: #fed7d7;
    color: #c53030;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    min-width: 60px;
    text-align: center;
}

.component .meaning {
    color: #4a5568;
    font-style: italic;
}

/* Rule Form */
.rule-form {
    display: grid;
    grid-template-columns: 150px 1fr 1fr auto;
    gap: 10px;
    align-items: center;
}

.rule-form select,
.rule-form input {
    padding: 8px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
}

.rule-form button {
    padding: 8px 16px;
    background: #48bb78;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
}

.rule-form button:hover {
    background: #38a169;
}

/* Pipeline Controls */
.pipeline-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
}

.pipeline-controls label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-size: 14px;
}

.pipeline-controls input[type="checkbox"] {
    margin: 0;
}

.pipeline-controls button {
    padding: 10px 20px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    margin-left: auto;
}

.pipeline-controls button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Break Insertion Modal */
.break-strategy {
    margin: 15px 0;
}

.break-strategy label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #4a5568;
}

.break-strategy select {
    width: 100%;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
}

.preview {
    margin: 20px 0;
}

.preview h4 {
    margin-bottom: 10px;
    color: #2d3748;
}

.preview textarea {
    width: 100%;
    height: 150px;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-family: 'Noto Sans Devanagari', monospace;
    font-size: 14px;
    background: #f7fafc;
    resize: none;
}

/* Validation Results */
.validation-results-modal .modal-content {
    max-width: 600px;
}

.tier-validation {
    margin: 15px 0;
    padding: 15px;
    border-radius: 8px;
    background: #f7fafc;
}

.tier-validation h4 {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tier-validation.valid {
    border-left: 4px solid #48bb78;
}

.tier-validation.invalid {
    border-left: 4px solid #f56565;
}

.issues {
    margin: 10px 0;
    padding-left: 20px;
}

.issues li {
    color: #e53e3e;
    margin: 5px 0;
}

/* Modal Buttons */
.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #e2e8f0;
}

.modal-content label[title] {
    cursor: help;
    border-bottom: 1px dotted #999;
    display: inline-block;
    margin-bottom: 5px;
}

.modal-content label[title]: hover {
    border-bottom-color: #333
}

.modal-buttons button {
    padding: 12px 24px;
    font-size: 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    min-width: 100px;
}

.modal-buttons button:first-child       {  background: #4299e1; color: white;   }
.modal-buttons button:first-child:hover {  background: #3182ce;                 }
.modal-buttons button:last-child        {  background: #e2e8f0; color: #4a5568; }
.modal-buttons button:last-child:hover  {  background: #cbd5e0;                 }

/* Status enhancements */
.status-bar.status-success { background: rgba(72, 187, 120, 0.9);  color: white;}
.status-bar.status-error   { background: rgba(245, 101, 101, 0.9); color: white;}
.status-bar.status-warning { background: rgba(237, 137, 54, 0.9);  color: white;}
.status-bar.status-info    { background: rgba(66, 153, 225, 0.9);  color: white;}


/* Source section styling */
.stage {
    margin-top: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 16px;
    border: 2px solid #e2e8f0;
    display: none; /* hidden by default (upon app startup) */
}

.stage.visible {
    display: block; 
}

.stage.minimized .stage-textarea {
    display: none; /* hide textarea when the section is minimized */
}

.stage-section.minimized {
    padding: 8px 16px; /* compact when minimized */
}
.stage-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.stage-header h2 {
    margin: 0; /* was 0 0 12px 0 */
    color: #374151;
    font-size: 18px;
}

.stage-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.stage-btn {
    font-size: clamp(12px, 2.5vw, 14px);
    padding: clamp(6px, 1.5vw, 10px) clamp(10px, 2.5vw, 16px);
    min-height: 36px;
    min-width: 60px;
    margin-right: 8px;
    border-radius: clamp(4px, 1vw, 6px);
    border: none;
    background: #6b7280;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    white-space: nowrap;
}

.stage-btn:hover {
    background: #4b5563;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.stage-btn:active {
    transform: translateY(0);
}

/* Special styling for primary actions */
.stage-btn#extract-selection {
    background: #059669;
}

.stage-btn#extract-selection:hover {
    background: #047857;
}

.stage-btn#new-empty-frame {
    background: #0ea5e9;
}

.stage-btn#new-empty-frame:hover {
    background: #0284c7;
}

/* Stage textarea */
.stage-textarea {
    width: 100%;
    min-height: 3em; /* was 120px but start small! */
    height: auto;
    font-family: 'Noto Sans Devanagari', 'Noto Sans', monospace;
    font-size: clamp(13px, 2vw, 15px);
    padding: clamp(8px, 1.5vw, 12px);
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: white;
    resize: vertical;
    margin-top: 12px;
}


/* Responsive button sizing based on viewport */
.main-controls button {
    /* Base size for desktop */
    font-size: clamp(12px, 2.5vw, 16px);
    padding: clamp(6px, 1.5vw, 12px) clamp(10px, 2.5vw, 20px);
    min-height: 28px;
    border-radius: clamp(4px, 1vw, 8px);
    
    /* Touch-friendly sizing */
    min-width: 60px;
    border: none;
    background: #4299e1;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.preference-item {
    margin-bottom: 16px;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8f9fa;
}

.preference-item:last-child {
    margin-bottom: 0;
}

.preference-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-weight: 500;
}

.preference-checkbox {
    margin-right: 8px;
    transform: scale(1.1);
}

.preference-description {
    font-size: 12px;
    color: #6b7280;
    margin-top: 4px;
    margin-left: 24px;
}

.frame-spinner-container {
    display: block;
}

.frame-navigation {
    display: none; 
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    margin: 16px 0;
    text-align: center;
}

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

.frame-btn {
    background: #6b7280;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s ease;
}

.frame-btn:hover {
    background: #4b5563;
}

.frame-btn:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

.frame-counter {
    font-weight: 500;
    color: #374151;
    min-width: 120px;
}

@media (max-width: 767px) {
    .frame-controls {
        flex-direction: column;
        gap: 8px;
    }
    
    .frame-btn {
        min-height: 44px;
        padding: 12px 20px;
        font-size: 16px;
    }
}

/* Tablet sizing */
@media (max-width: 1024px) and (min-width: 768px) {
    .main-controls button {
        min-height: 36px;
        font-size: 14px;
        padding: 8px 16px;
    }
}

/* Hover states */
.main-controls button:hover {
    background: #3182ce;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.main-controls button:active {
    transform: translateY(0);
}


/* Mobile sizing - larger touch targets */
@media (max-width: 767px) {

    .main-controls button {
        min-height: 44px;
        font-size: 16px;
        padding: 12px 20px;
        margin: 4px 2px;
    }
    .main-controls {
        flex-direction: column;
        gap: 8px;
    }

    
    .stage-btn {
        min-height: 44px;
        font-size: 16px;
        padding: 12px 20px;
        margin: 4px 2px;
	border-radius: clamp(4px, 1vw, 8px);
	min-width: 60px;
	border: none;
	background: #6b7280;
	color: white;
	cursor: pointer;
	transition: all 0.2s ease;
	margin-right: 8px;
    }

    .stage-btn:hover {
	background: #4b5563;
	transform: translateY(-1px);
	box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    }
    
    .stage-controls {
	margin-bottom: 12px;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    
    .stage-textarea {
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 100px;

    .stage-textarea {
	width: 100%;
	min-height: 120px;
	font-family: 'Noto Sans Devanagari', 'Noto Sans', monospace;
	font-size: clamp(13px, 2vw, 15px);
	padding: clamp(8px, 1.5vw, 12px);
	border: 1px solid #d1d5db;
	border-radius: 6px;
	background: white;
	resize: vertical;
	margin-top: 12px;
    }
    
    .modal-content {
        padding: 20px;
        margin: 10px;
    }
    
    .tool-controls,
    .dict-search {
        flex-direction: column;
        align-items: stretch;
    }
    
    .rule-form {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .pipeline-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .pipeline-controls button {
        margin-left: 0;
        margin-top: 10px;
    }
    
    .morph-button-group {
        justify-content: center;
    }

    .tier {
        flex-direction: column;
        padding: 6px;
	margin-bottom: 3px;
    }
    
    .tier-label {
        align-self: flex-start;
        margin-right: 0;
        margin-bottom: 6px;
    }
    
    .tier-controls {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .tier-content {
        max-height: 12em; /* Allow more height on mobile */
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

@media (max-width: 480px) {
    .morphology-tools-modal,
    .dictionary-manager-modal {
        padding: 5px;
    }
    
    .modal-content {
        padding: 15px;
        margin: 5px;
        max-height: 95vh;
    }
    
    .tool-section {
        padding: 10px;
    }
    
    .component {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
}

/* Responsive Design */
@media (max-width: 767px) {
    .container {
        padding: 15px;
        margin: 10px;
    }
    
    .header h1 {
        font-size: 2em;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .controls > div {
        display: flex;
        gap: 10px;
        justify-content: center;
    }
    
    .preferences-panel {
        width: 100%;
        right: -100%;
        margin: 0 -8px 16px -8px;
        border-radius: 0;
    }
    
    .preference-description {
        margin-left: 20px;
        font-size: 11px;
    }
    
    .tier-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .tier-controls {
        align-self: stretch;
        justify-content: center;
    }

    .stage-controls {
        flex-direction: column;
    }
    
    .stage-btn {
        min-height: 44px;
        font-size: 16px;
        padding: 12px 20px;
        margin: 0;
    }
}

@media (max-width: 480px) {
    .tier-controls {
        flex-direction: column;
    }
    
    .tier-controls .btn {
        padding: 8px 12px;
        font-size: 14px;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
        padding: 0;
    }
    
    .container {
        background: white;
        box-shadow: none;
        border-radius: 0;
    }
    
    .controls,
    .preferences-panel,
    .status-bar {
        display: none;
    }
    
    .tier-controls {
        display: none;
    }
    
    .tier {
        break-inside: avoid;
        margin-bottom: 20px;
    }
}
