/* ============================================================
   BanglaText Portal — Red & Green theme, light + dark modes.
   The two brand colors (Bangla red #c62828 and Bangla green
   #006a4e) drive every accent. Auto dark mode is opt-in via a
   toggle but defaults to `prefers-color-scheme`.
   ============================================================ */

:root {
  --red: #c62828;
  --red-soft: #e57373;
  --green: #006a4e;
  --green-soft: #2e7d5b;
  --green-bright: #0e7c3a;
  --bg: #fafaf6;
  --surface: #ffffff;
  --surface-2: #f3f5f1;
  --text: #1a2418;
  --muted: #5a6b58;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --bn-font: 'Noto Sans Bengali', 'Hind Siliguri', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10130f;
    --surface: #181c16;
    --surface-2: #20251d;
    --text: #ecf2e6;
    --muted: #9aa898;
    --border: rgba(255, 255, 255, 0.08);
    --shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
  }
}

[data-theme="dark"] {
  --bg: #10130f;
  --surface: #181c16;
  --surface-2: #20251d;
  --text: #ecf2e6;
  --muted: #9aa898;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
}

[data-theme="light"] {
  --bg: #fafaf6;
  --surface: #ffffff;
  --surface-2: #f3f5f1;
  --text: #1a2418;
  --muted: #5a6b58;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--bn-font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

/* ====================== Topbar ====================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--green) 0%, var(--green-bright) 60%, var(--red) 130%);
  color: #fff;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
  gap: 12px;
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: 0.3px; }
.brand .accent { color: #ffd479; }
.brand small { color: rgba(255,255,255,0.75); font-size: 13px; }

.logo-mark {
  display: inline-flex; gap: 4px; margin-right: 6px;
  align-self: center; padding-top: 2px;
}
.logo-mark .dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.logo-mark .red { background: var(--red); box-shadow: 0 0 0 2px rgba(255,255,255,0.4); }
.logo-mark .green { background: #00b272; box-shadow: 0 0 0 2px rgba(255,255,255,0.4); }

.tabs { display: flex; gap: 4px; background: rgba(0,0,0,0.18); padding: 4px; border-radius: 999px; }
.tab {
  background: transparent; border: 0; color: #fff;
  padding: 8px 18px; border-radius: 999px; cursor: pointer;
  font-size: 14px; font-weight: 500;
  transition: background 0.15s ease;
}
.tab:hover { background: rgba(255,255,255,0.12); }
.tab.active { background: #fff; color: var(--green); font-weight: 600; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.ws-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; background: rgba(0,0,0,0.18); border-radius: 999px;
  font-size: 13px;
}
.ws-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #ffd479; box-shadow: 0 0 6px #ffd479;
}
.ws-status.connected .ws-dot { background: #6fff9b; box-shadow: 0 0 6px #6fff9b; }
.ws-status.error .ws-dot { background: #ff8585; box-shadow: 0 0 6px #ff8585; }

.theme-toggle, .menu-toggle {
  background: rgba(0,0,0,0.18);
  border: 0; color: #fff;
  width: 36px; height: 36px; border-radius: 50%;
  cursor: pointer; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s ease;
}
.theme-toggle:hover, .menu-toggle:hover { transform: scale(1.1); }

.menu-toggle { display: none; }

/* ====================== Main / Panels ====================== */
html, body { height: 100%; }
body { display: flex; flex-direction: column; }
main { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; }

.panel { display: none; flex: 1; flex-direction: column; }
.panel.active { display: flex; animation: fadeIn 0.25s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

footer {
  text-align: center;
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
}

/* ====================== Typing panel ====================== */
.layout-switch {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 16px;
  background: var(--surface);
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.ls-label { color: var(--muted); margin-right: 4px; font-size: 14px; }
.ls-btn {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.ls-btn:hover { border-color: var(--green); }
.ls-btn.active {
  background: linear-gradient(135deg, var(--green), var(--green-bright));
  color: #fff; border-color: transparent;
  box-shadow: 0 2px 8px rgba(0, 106, 78, 0.3);
}

.typing-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  flex: 1;
}
@media (max-width: 900px) {
  .typing-grid { grid-template-columns: 1fr; }
}

.editor-card {
  display: flex;
  flex-direction: column;
}

.editor-card, .layout-card, .date-card, .img-controls, .img-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.editor-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px; margin-bottom: 12px;
}
.editor-head strong { font-size: 16px; }
.editor-head .hint {
  font-size: 13px; color: var(--muted); flex: 1;
  text-align: center;
}
.editor-actions { display: flex; gap: 6px; }
.editor-actions button {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  font-size: 13px;
}
.editor-actions button:hover { border-color: var(--red); color: var(--red); }

.raw-input {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
}
.raw-input label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.raw-input input {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  font-family: ui-monospace, monospace;
  font-size: 15px;
  padding: 6px 4px;
}

#banglaEditor {
  width: 100%;
  flex: 1;
  min-height: 200px;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 14px;
  font-size: 18px;
  line-height: 1.7;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#banglaEditor:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(0, 106, 78, 0.12);
}

.suggest-bar {
  margin-bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 38px;
}
.suggest-chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 15px;
  transition: all 0.12s ease;
  white-space: nowrap;
}

/* ====================== Mobile Optimizations ====================== */
@media (max-width: 600px) {
  .topbar { padding: 10px 16px; }
  .brand h1 { font-size: 18px; }
  .brand small { display: none; }
  .ws-label { display: none; }
  .ws-status { padding: 6px; }

  .menu-toggle { display: flex; }
  
  .tabs {
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--surface);
    border-radius: 0 0 var(--radius) var(--radius);
    padding: 10px;
    box-shadow: var(--shadow);
    display: none;
    z-index: 90;
    border-top: 1px solid var(--border);
  }
  .tabs.open { display: flex; animation: slideDown 0.2s ease-out; }
  @keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .tab { color: var(--text); border-radius: 8px; text-align: left; }
  .tab.active { background: var(--green); color: #fff; }

  main { padding: 12px; }
  footer { display: none; }

  .layout-switch {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 6px 10px;
    -webkit-overflow-scrolling: touch;
  }
  .ls-label { display: none; }
  .ls-btn { font-size: 13px; padding: 6px 12px; }

  .layout-card { display: none; }
  .editor-card { padding: 12px; flex: 1; }
  .editor-head .hint { display: none; }
  .editor-actions button span { display: none; }
  .editor-actions button { padding: 6px 8px; }
  
  .suggest-bar {
    flex-wrap: wrap;
    padding-bottom: 6px;
  }

  #banglaEditor { font-size: 16px; min-height: 150px; }
}

.suggest-chip:hover {
  background: linear-gradient(135deg, var(--green-bright), var(--green));
  color: #fff; border-color: transparent;
}
.suggest-chip.exact { border-color: var(--red); }
.suggest-chip.misspelled {
  border-color: var(--red);
  color: var(--red);
  background: rgba(198, 40, 40, 0.05);
}
.suggest-chip.preview {
  background: linear-gradient(135deg, var(--red), #b71c1c);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 0 0 2px rgba(198, 40, 40, 0.25);
  font-weight: 600;
}

.layout-card h3 {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--green);
  border-bottom: 2px solid var(--red);
  display: inline-block;
  padding-bottom: 4px;
}

.kbd-preview {
  display: grid; gap: 6px; font-family: ui-monospace, monospace;
}
.kbd-row { display: flex; gap: 4px; flex-wrap: wrap; }
.kbd-key {
  min-width: 38px;
  padding: 6px 4px;
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.kbd-key .roman { color: var(--muted); font-size: 10px; }
.kbd-key .bn { font-size: 14px; font-weight: 600; color: var(--green); }

.layout-info {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 10px;
  font-size: 13px;
  color: var(--muted);
  border-left: 3px solid var(--red);
}

/* ====================== Date panel ====================== */
.date-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.date-grid .wide { grid-column: 1 / -1; }
@media (max-width: 800px) {
  .date-grid { grid-template-columns: 1fr; }
}

.date-card h3 {
  margin: 0 0 12px;
  color: var(--green);
  border-bottom: 2px solid var(--red);
  display: inline-block;
  padding-bottom: 4px;
}
.date-card label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 12px 0 4px;
}
.date-card input[type="date"],
.date-card input[type="number"],
.date-card select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  outline: none;
  font-size: 15px;
}
.date-card input:focus, .date-card select:focus {
  border-color: var(--green);
}

.seg {
  display: flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 4px;
  border: 1px solid var(--border);
  flex-wrap: wrap;
}
.seg-btn {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}
.seg-btn.active {
  background: linear-gradient(135deg, var(--red), var(--red-soft));
  color: #fff;
}

.primary {
  margin-top: 14px;
  padding: 10px 18px;
  background: linear-gradient(135deg, var(--green), var(--green-bright));
  color: #fff;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  box-shadow: 0 2px 8px rgba(0, 106, 78, 0.3);
}
.primary:hover { transform: translateY(-1px); }

.result {
  margin-top: 14px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(0, 106, 78, 0.08), rgba(198, 40, 40, 0.08));
  border-radius: 10px;
  font-size: 18px;
  font-weight: 500;
  border-left: 4px solid var(--green);
  min-height: 30px;
}

.compare-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 700px) { .compare-row { grid-template-columns: 1fr; } }
.compare-row > div {
  padding: 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.compare-row h4 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--red);
}
.compare-row .big {
  font-size: 22px;
  font-weight: 600;
  color: var(--green);
}
.note {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 8px;
  border-left: 3px solid var(--red);
}

.rule-tag {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.check-label input[type="checkbox"] {
  margin: 0;
  accent-color: var(--green);
}
.check-label.inline {
  margin-right: 8px;
  color: var(--muted);
}

/* ====================== Image panel ====================== */
.image-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
}
@media (max-width: 1000px) {
  .image-grid { grid-template-columns: 1fr; }
}

.img-controls h3 {
  margin: 0 0 12px;
  color: var(--green);
  border-bottom: 2px solid var(--red);
  display: inline-block;
  padding-bottom: 4px;
}
.img-controls label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 12px 0 4px;
}
.img-controls input, .img-controls select, .img-controls textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  outline: none;
  font-size: 14px;
}
.img-controls textarea { min-height: 80px; resize: vertical; }
.img-controls input[type="color"] { padding: 2px; height: 38px; cursor: pointer; }

.row2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin-top: 4px;
}
.row2 button { margin-top: 22px; }

.img-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  background: repeating-conic-gradient(var(--surface-2) 0% 25%, var(--surface) 0% 50%) 50% / 24px 24px;
  min-height: 540px;
  overflow: auto;
}
#t2iCanvas {
  max-width: 100%;
  height: auto;
  background: #fff;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.15);
  border-radius: 6px;
}

/* Unicode to Bijoy Converter */
.converter-container {
  display: flex; flex-direction: column; gap: 20px; max-width: 900px; margin: 0 auto;
}
.converter-box {
  background: var(--surface); padding: 20px; border-radius: 12px;
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
.converter-box h3 {
  margin: 0 0 12px; color: var(--green); border-bottom: 2px solid var(--red);
  display: inline-block; padding-bottom: 4px; font-size: 16px;
}
.converter-box textarea {
  width: 100%; min-height: 200px; padding: 15px; font-size: 1.1rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
  color: var(--text); resize: vertical; line-height: 1.6; outline: none;
}
.converter-box textarea:focus { border-color: var(--green); }
.converter-actions {
  display: flex; justify-content: center; gap: 15px; align-items: center;
}
.converter-actions button {
  padding: 12px 24px; font-size: 1rem; font-weight: 600;
}
