/* ==========================================================================
   Breaking Words — Olive Green Theme & Sharp Breaking Bad Styling
   ========================================================================== */

:root {
  --page-bg: #556b2f; /* Olive Green */
  --surface: rgba(18, 29, 10, 0.38);
  --surface-strong: rgba(14, 23, 8, 0.56);
  --modal-bg: #182312;
  --modal-subtle: #22311a;
  --text: #f8faf5;
  --text-muted: #d9e3c8;
  --border: rgba(255, 255, 255, 0.2);
  --border-strong: rgba(255, 255, 255, 0.36);
  --accent: #1f6f43;
  --accent-bright: #34d399;
  --accent-hover: #175834;
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.18);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 24px 55px rgba(0, 0, 0, 0.5);
  --font-sans: "Bitstream Vera Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  border-radius: 0 !important;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--page-bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.brand-name {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.brand:hover .brand-name {
  color: #ffffff;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 14px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease, color 0.15s ease;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn-sm {
  font-size: 13px;
  padding: 7px 12px;
}

.btn-primary {
  background: var(--accent);
  border-color: #6ee7b7;
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.22);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.38);
}

.btn-ghost {
  background: var(--surface);
  color: #ffffff;
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--surface-strong);
  border-color: var(--border-strong);
}

/* Main Content */
.main-content {
  flex: 1;
  max-width: 1040px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Hero & [Br]eaking [W]ords Lockup */
.hero {
  text-align: center;
  padding: 6px 0 4px;
}

.hero-title {
  margin: 0 0 12px;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: clamp(32px, 5vw, 48px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.title-word {
  display: inline-flex;
  align-items: center;
}

.title-tile {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.42em;
  height: 1.42em;
  margin-right: 4px;
  background: linear-gradient(155deg, #1f6f43 0%, #114428 55%, #0a2e1a 100%);
  border: 2px solid #6ee7b7;
  color: #ffffff;
  font-size: 0.92em;
  font-weight: 800;
  letter-spacing: -0.03em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 6px 18px rgba(0, 0, 0, 0.38);
  text-shadow: none;
}

.title-tile-num {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: 0.26em;
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1;
  opacity: 0.9;
}

.hero-subtitle {
  margin: 0 0 22px;
  color: var(--text-muted);
  font-size: 15.5px;
}

.search-box-wrap {
  max-width: 680px;
  margin: 0 auto;
}

.search-box {
  display: flex;
  align-items: center;
  background: #ffffff;
  border: 2px solid rgba(0, 0, 0, 0.35);
  padding: 6px 10px 6px 18px;
  box-shadow: var(--shadow-md);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.search-box:focus-within {
  border-color: #6ee7b7;
  box-shadow: 0 0 0 4px rgba(110, 231, 183, 0.28), var(--shadow-md);
}

.word-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: #141f0d;
  font-family: inherit;
  font-size: 20px;
  font-weight: 600;
  padding: 8px 0;
}

.word-input::placeholder {
  color: #64748b;
  font-weight: 400;
}

.input-clear-btn {
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 24px;
  line-height: 1;
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.input-clear-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}

/* Controls Bar */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 11px 16px;
  backdrop-filter: blur(6px);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.control-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.segmented {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.28);
  padding: 3px;
  border: 1px solid var(--border);
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.seg-btn.active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.control-toggles {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
  cursor: pointer;
  user-select: none;
}

.toggle-chip input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  width: 34px;
  height: 20px;
  background: rgba(0, 0, 0, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.28);
  position: relative;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  transition: transform 0.18s ease;
}

.toggle-chip input:checked + .toggle-track {
  background: #1f6f43;
  border-color: #6ee7b7;
}

.toggle-chip input:checked + .toggle-track::after {
  transform: translateX(14px);
}

/* Status Banner */
.status-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(20, 30, 10, 0.65);
  border: 1px solid #fcd34d;
  color: #fef08a;
  font-size: 14px;
  font-weight: 500;
}

.status-banner-text {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Stage Card — Sharp Breaking Bad Default */
.stage-card {
  background: radial-gradient(circle at 50% 25%, #0e2e1d 0%, #05130c 100%);
  border: 1px solid rgba(110, 231, 183, 0.35);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.tiles-stage {
  min-height: 205px;
  padding: 38px 24px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.names-readout {
  text-align: center;
  padding: 0 24px 22px;
  font-size: 14.5px;
  font-weight: 600;
  color: #a7f3d0;
}

.names-readout:empty {
  display: none;
}

.empty-stage {
  text-align: center;
  color: rgba(209, 250, 229, 0.65);
  padding: 20px;
}

.empty-stage p {
  margin: 6px 0 0;
  font-size: 15px;
}

/* Sharp Breaking Bad Element Tiles */
.el-tile {
  position: relative;
  width: 110px;
  height: 122px;
  border: 2px solid #6ee7b7;
  background: linear-gradient(155deg, #1f6f43 0%, #114428 55%, #0a2e1a 100%);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 6px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.16s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.16s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 8px 20px rgba(0, 0, 0, 0.45);
}

.el-tile:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 12px 26px rgba(0, 0, 0, 0.6);
  z-index: 3;
}

.el-tile-inner {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Horizontal mirror for reversed elements (He->eh, Ne->en, Mn->nm, Ru->ur, Mo->om) */
.el-tile.is-reversed .el-tile-inner {
  transform: scaleX(-1);
}

.el-tile-num {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 12.5px;
  font-weight: 700;
  font-family: var(--font-mono);
  opacity: 0.9;
}

.el-tile-mass {
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 10px;
  font-weight: 600;
  font-family: var(--font-mono);
  opacity: 0.75;
}

.el-tile-symbol {
  font-size: 44px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  margin-top: 6px;
}

.el-tile-symbol sup {
  font-size: 22px;
  position: relative;
  top: -14px;
}

.el-tile-name {
  font-size: 11.5px;
  font-weight: 600;
  margin-top: 7px;
  max-width: 98px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.92;
}

/* Unmatched fallback tile */
.el-tile.is-unmatched {
  border-style: dashed;
  border-color: rgba(110, 231, 183, 0.35);
  background: transparent;
  color: rgba(209, 250, 229, 0.55);
  cursor: default;
  box-shadow: none;
}

.el-tile.is-unmatched:hover {
  transform: none;
  box-shadow: none;
}

/* Word Space & Punctuation */
.tile-space {
  width: 28px;
  height: 122px;
}

.tile-punct {
  font-size: 38px;
  font-weight: 800;
  color: #6ee7b7;
  padding: 0 6px;
  user-select: none;
}

/* Stage Footer */
.stage-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: rgba(0, 0, 0, 0.32);
  border-top: 1px solid rgba(110, 231, 183, 0.2);
}

.stage-meta {
  font-size: 13px;
  color: #86efac;
  font-weight: 500;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Alternatives Section */
.alternatives-section {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 16px 20px;
  backdrop-filter: blur(6px);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
}

.badge {
  background: rgba(16, 185, 129, 0.25);
  border: 1px solid rgba(110, 231, 183, 0.4);
  color: #a7f3d0;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 9px;
}

.alternatives-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.alt-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  color: #f8faf5;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s ease;
}

.alt-pill:hover {
  border-color: #6ee7b7;
  background: rgba(31, 111, 67, 0.4);
}

.alt-pill.active {
  background: #1f6f43;
  border-color: #6ee7b7;
  color: #ffffff;
}

/* Footer */
.footer {
  text-align: center;
  padding: 18px 24px 30px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 14, 5, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-card {
  position: relative;
  background: var(--modal-bg);
  color: #f8faf5;
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
  width: 100%;
}

.modal-sm {
  max-width: 460px;
}

.modal-xl {
  max-width: 1120px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: var(--modal-subtle);
  border: 1px solid var(--border);
  color: #ffffff;
  width: 32px;
  height: 32px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

.modal-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding-right: 40px;
  margin-bottom: 14px;
}

.modal-header-row h3 {
  margin: 0;
  font-size: 20px;
}

.modal-hint {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.modal-element-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.modal-tile-preview {
  width: 82px;
  height: 88px;
  border: 2px solid #6ee7b7;
  background: linear-gradient(155deg, #1f6f43 0%, #0a2e1a 100%);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.modal-category-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  margin-bottom: 6px;
}

.modal-element-meta h3 {
  margin: 0;
  font-size: 22px;
}

.modal-subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.modal-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat-box {
  background: var(--modal-subtle);
  border: 1px solid var(--border);
  padding: 10px 12px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.stat-val {
  font-size: 15px;
  font-weight: 700;
  margin-top: 2px;
}

.modal-wiki-extract {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text-muted);
  background: var(--modal-subtle);
  border: 1px solid var(--border);
  padding: 11px 13px;
  margin: 0 0 16px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.modal-actions .btn {
  flex: 1;
}

/* Periodic Table Grid */
.pt-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
}

.pt-scroll-wrap {
  overflow-x: auto;
  padding-bottom: 6px;
}

.pt-grid {
  display: grid;
  grid-template-columns: repeat(18, minmax(46px, 1fr));
  grid-template-rows: repeat(10, 52px);
  gap: 4px;
  min-width: 880px;
}

.pt-cell {
  border: 1.5px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  padding: 2px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.pt-cell:hover {
  transform: scale(1.14);
  z-index: 5;
  box-shadow: var(--shadow-md);
}

.pt-cell-num {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 8px;
  font-weight: 700;
  opacity: 0.85;
}

.pt-cell-sym {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.1;
}

.pt-cell-name {
  font-size: 7.5px;
  max-width: 44px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.85;
}

.pt-extra-wrap {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.pt-extra-wrap h4 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-muted);
}

.pt-extra-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
}

.pt-extra-row .pt-cell {
  height: 54px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0a1408;
  border: 1px solid #6ee7b7;
  color: #ffffff;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 200;
}

/* Responsive */
@media (max-width: 640px) {
  .topbar {
    padding: 14px 16px;
  }
  .main-content {
    padding: 8px 16px 36px;
  }
  .hero-title {
    gap: 10px;
  }
  .word-input {
    font-size: 17px;
  }
  .el-tile {
    width: 82px;
    height: 94px;
  }
  .el-tile-symbol {
    font-size: 32px;
  }
  .el-tile-mass {
    display: none;
  }
  .tiles-stage {
    padding: 26px 12px 16px;
    gap: 8px;
  }
}
