/* ============================================
   HTML Entity Encoder / Decoder
   ============================================ */

html {
  background-color: #0d9488;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.05) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
  animation: float 20s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(5deg); }
}

/* ======================
   HEADER
   ====================== */

.header {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  padding: var(--space-3) 0;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.header-content {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.logo-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  color: white;
  transition: all var(--transition-base);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(5px);
  flex-shrink: 0;
}

.logo-link:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.logo-text { color: white; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); }
.logo-dot { color: #fbbf24; animation: pulse 2s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.2); }
}

.title {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* ======================
   TAB NAVIGATION
   ====================== */

.tabs-nav {
  display: flex;
  gap: var(--space-2);
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  padding: var(--space-2) var(--space-4);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: rgba(255, 255, 255, 0.7);
  font-weight: var(--font-medium);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--transition-base);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.tab-btn:hover { background: rgba(255, 255, 255, 0.1); color: rgba(255, 255, 255, 0.9); }
.tab-btn.active { color: white; border-bottom-color: white; background: rgba(255, 255, 255, 0.2); font-weight: var(--font-semibold); }
.tab-icon { font-size: var(--text-xl); }
.tab-label { font-size: var(--text-sm); }

/* ======================
   MODE SELECTOR
   ====================== */

.mode-selector {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  padding: var(--space-3) 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.mode-selector-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.mode-selector-left { display: flex; gap: var(--space-2); flex: 1; min-width: 0; }
.mode-selector-right { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }

.mode-buttons { display: flex; gap: var(--space-2); }

.mode-btn {
  padding: var(--space-2) var(--space-4);
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-md);
  color: white;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: all var(--transition-base);
  white-space: nowrap;
}

.mode-btn:hover { background: rgba(255, 255, 255, 0.3); transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); }
.mode-btn.active { background: rgba(255, 255, 255, 0.4); border-color: rgba(255, 255, 255, 0.5); font-weight: var(--font-semibold); }

.auto-execute-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all var(--transition-base);
  user-select: none;
}

.auto-execute-toggle:hover { background: rgba(255, 255, 255, 0.25); }
.auto-execute-toggle:has(input:checked) { background: rgba(16, 185, 129, 0.3); border-color: rgba(16, 185, 129, 0.5); }
.auto-execute-toggle input[type="checkbox"] { width: 14px; height: 14px; accent-color: #10b981; cursor: pointer; margin: 0; }
.auto-execute-label { color: white; font-size: var(--text-xs); font-weight: var(--font-semibold); letter-spacing: 0.02em; }

/* ======================
   PAGE BODY
   ====================== */

.page-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  grid-template-areas: "content";
  min-height: 0;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.hidden { display: none !important; }

/* ======================
   AD SIDEBARS
   ====================== */

.ad-sidebar { display: none; align-self: center; padding: var(--space-4) 0; }
.ad-sidebar-left { grid-area: ad-left; justify-self: center; }
.ad-sidebar-right { grid-area: ad-right; justify-self: center; }
.ad-sticky { position: sticky; top: var(--space-4); }

.ad-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 160px;
  height: 600px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 2px dashed rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-md);
  color: rgba(255, 255, 255, 0.6);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.4;
}

/* ======================
   MAIN CONTENT
   ====================== */

.main-content {
  grid-area: content;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: var(--space-4) 0;
  min-height: 0;
}

/* ======================
   PANELS
   ====================== */

.panels-container {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
  min-height: 0;
}

@media (min-width: 1024px) {
  .panels-container { grid-template-columns: 1fr 1fr; }
}

.panel {
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.95);
  border-radius: var(--radius-xl);
  border: 1px solid rgba(255, 255, 255, 0.3);
  overflow: hidden;
  min-height: 0;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.1);
  transition: box-shadow var(--transition-base);
}

.panel:hover {
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  background: linear-gradient(135deg, rgba(13, 148, 136, 0.1), rgba(15, 118, 110, 0.1));
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.panel-title { font-size: var(--text-lg); font-weight: var(--font-bold); color: var(--color-gray-900); }

.btn-icon {
  background: rgba(13, 148, 136, 0.1);
  border: none;
  cursor: pointer;
  font-size: var(--text-xl);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
  color: var(--color-gray-700);
}

.btn-icon:hover { background: rgba(13, 148, 136, 0.2); transform: scale(1.1); }
.panel-actions { display: flex; align-items: center; gap: var(--space-1); }

.panel-body {
  flex: 1;
  padding: var(--space-4);
  overflow: hidden;
  display: flex;
  min-height: 0;
}

.panel-body .textarea {
  flex: 1;
  min-height: 0;
  resize: none;
  font-size: var(--text-sm);
  line-height: 1.6;
  border: none;
  background: transparent;
  color: var(--color-gray-900);
}

.panel-body .textarea:focus { outline: none; box-shadow: none; }

/* ======================
   REFERENCE TAB
   ====================== */

.reference-body {
  flex: 1;
  overflow: auto;
  position: relative;
  z-index: 1;
}

.reference-content {
  padding: var(--space-6) 0;
  overflow: auto;
  flex: unset;
  height: 100%;
}

.reference-container {
  padding-bottom: var(--space-8);
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--space-4);
}

.ref-group {
  background: rgba(255, 255, 255, 0.95);
  border-radius: var(--radius-xl);
  border: 1px solid rgba(255, 255, 255, 0.3);
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.ref-group-title {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  color: var(--color-gray-800);
  background: linear-gradient(135deg, rgba(13, 148, 136, 0.1), rgba(15, 118, 110, 0.1));
  border-bottom: 1px solid var(--color-border);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: var(--text-xs);
  color: #5b21b6;
}

.ref-table { width: 100%; border-collapse: collapse; }

.ref-table thead th {
  padding: var(--space-2) var(--space-3);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--color-gray-600);
  background: var(--color-gray-50);
  border-bottom: 1px solid var(--color-gray-200);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ref-row {
  cursor: pointer;
  transition: background var(--transition-fast);
}

.ref-row:hover { background: rgba(13, 148, 136, 0.06); }
.ref-row:not(:last-child) td { border-bottom: 1px solid var(--color-gray-100); }

.ref-row td { padding: var(--space-2) var(--space-3); font-size: var(--text-sm); }

.ref-entity code {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: rgba(13, 148, 136, 0.1);
  color: #5b21b6;
  padding: 2px 5px;
  border-radius: 3px;
}

.ref-char {
  font-size: var(--text-lg);
  text-align: center;
  color: var(--color-gray-800);
  font-weight: var(--font-semibold);
  width: 48px;
}

.ref-desc { color: var(--color-gray-600); font-size: var(--text-xs); }

/* ======================
   STATUS BAR
   ====================== */

.status-bar {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  padding: var(--space-2) 0;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.status-content { display: flex; align-items: center; gap: var(--space-6); font-size: var(--text-sm); }
.status-item { display: flex; align-items: center; gap: var(--space-2); }
.status-label { color: rgba(255, 255, 255, 0.8); font-weight: var(--font-medium); }
#char-count, #status-mode, #status-text { color: white; font-weight: var(--font-semibold); }

/* ============================================
   RESPONSIVE: Wide Desktop (>= 1400px)
   ============================================ */

@media (min-width: 1400px) {
  .page-body {
    grid-template-columns: 200px 1fr 200px;
    grid-template-areas: "ad-left content ad-right";
  }
  .ad-sidebar { display: block; }
}

/* ============================================
   RESPONSIVE: Mobile (< 768px)
   ============================================ */

@media (max-width: 767px) {
  body { height: auto; min-height: 100vh; min-height: 100dvh; overflow-y: auto; }

  .page-body { overflow: visible; min-height: auto; }
  .main-content { padding: var(--space-2) 0; overflow: visible; }
  .panels-container { grid-template-columns: 1fr; grid-template-rows: auto auto; gap: var(--space-2); }
  .panel { min-height: 40vh; }
  .panel-header { padding: var(--space-2) var(--space-3); }
  .panel-title { font-size: var(--text-sm); }
  .panel-body { padding: var(--space-2) var(--space-3); overflow: auto; }

  .header { padding: var(--space-2) 0; }
  .title { font-size: var(--text-sm); }
  .logo-link { font-size: var(--text-sm); padding: var(--space-1) var(--space-2); }

  .tab-btn { flex-direction: row; font-size: var(--text-xs); padding: var(--space-2) var(--space-3); gap: var(--space-2); }
  .tab-icon { font-size: var(--text-base); }
  .tab-label { font-size: var(--text-xs); }

  .mode-selector-right { gap: var(--space-1); }
  #btn-example { display: none; }
  .btn-sm { padding: var(--space-2) var(--space-3); font-size: var(--text-sm); }

  .status-bar { padding: var(--space-1) 0; }
  .status-content { gap: var(--space-2); font-size: var(--text-xs); }

  .reference-grid { grid-template-columns: 1fr; }
  .reference-content { height: auto; }
  .reference-body { overflow: visible; }
}

/* ============================================
   DARK MODE
   ============================================ */

html[data-theme="dark"] { background-color: #0f172a; }

[data-theme="dark"] body { background: #0f172a; }
[data-theme="dark"] .header { background: rgba(0, 0, 0, 0.3); border-bottom-color: rgba(255, 255, 255, 0.1); }
[data-theme="dark"] .tabs-nav { background: rgba(0, 0, 0, 0.3); border-bottom-color: rgba(255, 255, 255, 0.1); }
[data-theme="dark"] .mode-selector { background: rgba(0, 0, 0, 0.2); border-bottom-color: rgba(255, 255, 255, 0.1); }
[data-theme="dark"] .mode-btn { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.15); }
[data-theme="dark"] .mode-btn.active { background: rgba(255, 255, 255, 0.25); border-color: rgba(255, 255, 255, 0.3); }

[data-theme="dark"] .panel {
  background: rgba(15, 23, 42, 0.95);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
}
[data-theme="dark"] .panel:hover {
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.1);
}
[data-theme="dark"] .panel-header { background: linear-gradient(135deg, rgba(13, 148, 136, 0.15), rgba(15, 118, 110, 0.15)); border-bottom-color: rgba(255, 255, 255, 0.1); }
[data-theme="dark"] .panel-title { color: var(--color-gray-100); }
[data-theme="dark"] .btn-icon { background: rgba(13, 148, 136, 0.2); color: var(--color-gray-300); }
[data-theme="dark"] .btn-icon:hover { background: rgba(13, 148, 136, 0.3); }
[data-theme="dark"] .panel-body .textarea { color: var(--color-gray-100); }
[data-theme="dark"] .panel-body .textarea::placeholder { color: var(--color-gray-500); }

[data-theme="dark"] .status-bar { background: rgba(0, 0, 0, 0.3); border-top-color: rgba(255, 255, 255, 0.1); }
[data-theme="dark"] .auto-execute-toggle { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.15); }
[data-theme="dark"] .auto-execute-toggle:has(input:checked) { background: rgba(16, 185, 129, 0.25); border-color: rgba(16, 185, 129, 0.4); }
[data-theme="dark"] .ad-placeholder { background: rgba(0, 0, 0, 0.2); border-color: rgba(255, 255, 255, 0.15); }

[data-theme="dark"] .ref-group {
  background: rgba(15, 23, 42, 0.95);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
[data-theme="dark"] .ref-group-title { background: linear-gradient(135deg, rgba(13, 148, 136, 0.15), rgba(15, 118, 110, 0.15)); border-bottom-color: rgba(255, 255, 255, 0.1); color: #2dd4bf; }
[data-theme="dark"] .ref-table thead th { background: rgba(255, 255, 255, 0.05); border-bottom-color: rgba(255, 255, 255, 0.1); color: var(--color-gray-400); }
[data-theme="dark"] .ref-row:hover { background: rgba(13, 148, 136, 0.12); }
[data-theme="dark"] .ref-row:not(:last-child) td { border-bottom-color: rgba(255, 255, 255, 0.06); }
[data-theme="dark"] .ref-entity code { background: rgba(45, 212, 191, 0.15); color: #2dd4bf; }
[data-theme="dark"] .ref-char { color: var(--color-gray-200); }
[data-theme="dark"] .ref-desc { color: var(--color-gray-400); }

/* ── About/Related fix: allow scrolling past tool UI ─────────────────────── */
.main-content { overflow-y: auto; }
.panels-container { min-height: clamp(350px, 60vh, 800px); }

/* ── Compact header ─────────────────────────────────────────────────────── */
.header { padding: var(--space-1) 0; }
.logo-link { font-size: var(--text-sm); padding: var(--space-1) var(--space-2); }
.title { font-size: var(--text-sm); }

/* ── Mobile: natural page scroll + usable editor height ─────────────────── */
@media (max-width: 767px) {
  body { height: auto; min-height: 100vh; overflow-y: auto; }
  .page-body { overflow: visible; }
  .main-content { overflow: visible !important; padding-bottom: var(--space-8); }
  .panel { min-height: 42vh; }
}
