:root {
  color-scheme: light;
  --table-width: 1239px;
  --page-pad: clamp(18px, 3vw, 40px);
  --gap: 3px;
  --cell-size: min(
    66px,
    calc((100vw - var(--page-pad) - var(--page-pad) - 51px) / 18)
  );
  --bg: #f5f6f4;
  --surface: #ffffff;
  --ink: #151821;
  --muted: #66707a;
  --line: #d2d7d2;
  --accent: #087f8c;
  --panel: #ffffff;
  --panel-line: #d5dde5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 34px var(--page-pad) 40px;
}

.workspace,
.app-shell > * {
  min-width: 0;
}

.workspace {
  width: 100%;
  max-width: var(--table-width);
  margin-inline: auto;
}

.site-meta {
  width: 100%;
  max-width: var(--table-width);
  margin: auto auto 0;
  padding-top: 24px;
  text-align: right;
}

.copyright-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.3;
}

.visit-counter {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 1.3;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 760;
  letter-spacing: 0;
}

.language-switcher {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  padding: 3px;
}

.language-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 32px;
  min-height: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  padding: 0;
  text-decoration: none;
}

.language-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: rgba(8, 127, 140, 0.12);
}

.language-button:hover {
  background: #edf2f5;
}

.language-button:focus-visible {
  outline: 2px solid rgba(8, 127, 140, 0.24);
  outline-offset: 2px;
}

.flag {
  width: 22px;
  height: 15px;
  border: 1px solid rgba(32, 38, 46, 0.22);
  border-radius: 2px;
  box-shadow: 0 1px 1px rgba(24, 32, 42, 0.12);
}

.flag-pl {
  background: linear-gradient(#fff 0 50%, #dc143c 50% 100%);
}

.flag-en {
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 30'%3E%3Cpath fill='%23012169' d='M0 0h60v30H0z'/%3E%3Cpath stroke='%23fff' stroke-width='6' d='m0 0 60 30M60 0 0 30'/%3E%3Cpath stroke='%23c8102e' stroke-width='3' d='m0 0 60 30M60 0 0 30'/%3E%3Cpath stroke='%23fff' stroke-width='10' d='M30 0v30M0 15h60'/%3E%3Cpath stroke='%23c8102e' stroke-width='6' d='M30 0v30M0 15h60'/%3E%3C/svg%3E")
    center / cover no-repeat;
}

.spectrum-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: stretch;
  min-width: 0;
  width: 100%;
  margin-bottom: 22px;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 14px;
}

.spectrum-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 104px;
  overflow: hidden;
  border: 1px solid #d5dde5;
  border-radius: 6px;
  background: #ffffff;
}

.spectrum-frame img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

.table-scroll {
  width: 100%;
  overflow: visible;
  padding-bottom: 0;
}

.periodic-grid {
  display: grid;
  grid-template-columns: repeat(18, minmax(0, 1fr));
  grid-template-rows: repeat(9, var(--cell-size));
  gap: var(--gap);
  width: 100%;
  min-width: 0;
}

.element-tile {
  --tile-bg: #314452;
  --tile-border: #182631;
  --tile-glow: rgba(10, 34, 51, 0.38);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 100%;
  height: 100%;
  border: 1px solid var(--tile-border);
  border-radius: 7px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(0, 0, 0, 0.08)),
    var(--tile-bg);
  color: #ffffff;
  cursor: pointer;
  isolation: isolate;
  transition:
    background-color 160ms ease,
    border-color 160ms ease,
    filter 160ms ease,
    transform 180ms ease,
    box-shadow 180ms ease;
}

.element-tile[data-category="alkali"],
.selected-preview[data-category="alkali"] {
  --tile-bg: #d95511;
  --tile-border: #8e2f04;
  --tile-glow: rgba(217, 85, 17, 0.45);
}

.element-tile[data-category="alkaline"],
.selected-preview[data-category="alkaline"] {
  --tile-bg: #c18f00;
  --tile-border: #7d5a00;
  --tile-glow: rgba(193, 143, 0, 0.45);
}

.element-tile[data-category="transition"],
.selected-preview[data-category="transition"] {
  --tile-bg: #006da6;
  --tile-border: #003f66;
  --tile-glow: rgba(0, 109, 166, 0.45);
}

.element-tile[data-category="post-transition"],
.selected-preview[data-category="post-transition"] {
  --tile-bg: #087f72;
  --tile-border: #004f47;
  --tile-glow: rgba(8, 127, 114, 0.45);
}

.element-tile[data-category="metalloid"],
.selected-preview[data-category="metalloid"] {
  --tile-bg: #4f8f18;
  --tile-border: #2f5d07;
  --tile-glow: rgba(79, 143, 24, 0.45);
}

.element-tile[data-category="polyatomic"],
.selected-preview[data-category="polyatomic"] {
  --tile-bg: #087f32;
  --tile-border: #004f1d;
  --tile-glow: rgba(8, 127, 50, 0.45);
}

.element-tile[data-category="diatomic"],
.selected-preview[data-category="diatomic"] {
  --tile-bg: #007f9f;
  --tile-border: #004d62;
  --tile-glow: rgba(0, 127, 159, 0.45);
}

.element-tile[data-category="noble"],
.selected-preview[data-category="noble"] {
  --tile-bg: #4e39a8;
  --tile-border: #291b71;
  --tile-glow: rgba(78, 57, 168, 0.45);
}

.element-tile[data-category="lanthanide"],
.selected-preview[data-category="lanthanide"] {
  --tile-bg: #b61970;
  --tile-border: #740943;
  --tile-glow: rgba(182, 25, 112, 0.45);
}

.element-tile[data-category="actinide"],
.selected-preview[data-category="actinide"] {
  --tile-bg: #742bb4;
  --tile-border: #45156f;
  --tile-glow: rgba(116, 43, 180, 0.45);
}

.element-tile:hover:not(:disabled) {
  z-index: 2;
  border-color: #ffffff;
  filter: saturate(1.22) contrast(1.03);
  transform: translateY(-5px) scale(1.06);
  box-shadow:
    0 0 0 2px rgba(17, 19, 24, 0.12),
    0 14px 28px var(--tile-glow);
}

.element-tile:hover:not(:disabled) .symbol {
  transform: scale(1.06);
}

.element-tile:focus-visible {
  outline: 3px solid rgba(8, 127, 140, 0.36);
  outline-offset: 2px;
}

.element-tile.is-active {
  border-color: #ffffff;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.72),
    0 0 0 2px var(--accent),
    0 12px 26px var(--tile-glow);
}

.element-tile:disabled,
.element-tile[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.45;
  filter: grayscale(0.45);
}

.element-tile[data-refresh-tile="true"] {
  cursor: pointer;
}

.element-tile[data-refresh-tile="true"][data-has-spectrum="false"] {
  opacity: 0.45;
  filter: grayscale(0.45);
}

.element-tile[data-refresh-tile="true"][aria-busy="true"] {
  filter: saturate(0.85) brightness(1.08);
}

.selected-preview {
  --tile-bg: #314452;
  --tile-border: #182631;
  --tile-glow: rgba(10, 34, 51, 0.38);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-self: center;
  align-self: center;
  justify-content: center;
  gap: clamp(2px, calc(var(--cell-size) * 0.07), 6px);
  width: calc(var(--cell-size) * 2.18);
  height: calc(var(--cell-size) * 2.18);
  border: 1px solid var(--tile-border);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(0, 0, 0, 0.1)),
    var(--tile-bg);
  color: #ffffff;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.16),
    0 14px 30px var(--tile-glow);
  padding: clamp(7px, calc(var(--cell-size) * 0.16), 16px);
  overflow: hidden;
}

.preview-number {
  position: absolute;
  top: clamp(5px, calc(var(--cell-size) * 0.12), 9px);
  left: clamp(6px, calc(var(--cell-size) * 0.13), 10px);
  font-size: clamp(0.58rem, calc(var(--cell-size) * 0.2), 0.95rem);
  font-weight: 760;
  line-height: 1;
  opacity: 0.84;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
}

.preview-symbol {
  font-size: clamp(1.75rem, calc(var(--cell-size) * 0.98), 4.35rem);
  font-weight: 850;
  line-height: 0.9;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.34);
}

.preview-name {
  min-width: 0;
  max-width: 100%;
  font-size: clamp(0.68rem, calc(var(--cell-size) * 0.27), 1.45rem);
  font-weight: 780;
  line-height: 1.05;
  text-align: center;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.34);
}

.number {
  position: absolute;
  top: 5px;
  left: 6px;
  font-size: clamp(0.38rem, calc(var(--cell-size) * 0.13), 0.58rem);
  font-weight: 760;
  line-height: 1;
  opacity: 0.78;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
}

.symbol {
  display: block;
  font-size: clamp(0.62rem, calc(var(--cell-size) * 0.29), 1.18rem);
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.34);
  transition: transform 180ms ease;
}

.name {
  display: block;
  max-width: 100%;
  padding: 0 4px;
  overflow-wrap: anywhere;
  text-align: center;
  font-size: clamp(0.34rem, calc(var(--cell-size) * 0.13), 0.55rem);
  font-weight: 690;
  line-height: 1.05;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.32);
}

@media (max-width: 700px) {
  .app-shell {
    padding: 22px 18px 28px;
  }

  h1 {
    font-size: 1.55rem;
  }
}
