:root {
  --accent: #ff3030;
  --bg: #f4f4f5;
  --surface: #fafafa;
  --surface-2: #ffffff;
  --text: #000000;
  --text-muted: #71717a;
  --text-dim: #52525b;
  --border: #e4e4e7;
  --border-strong: #e5e5e5;
  --panel: #fafafa;
  --dot: #d4d4d8;
  --btn-digit-bg: #fafafa;
  --btn-action: #27272a;
  --shadow: rgba(0, 0, 0, 0.08);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Mono", "Consolas", monospace;
}

[data-theme="dark"] {
  --bg: #000000;
  --surface: #09090b;
  --surface-2: #18181b;
  --text: #ffffff;
  --text-muted: #a1a1aa;
  --text-dim: #52525b;
  --border: #27272a;
  --border-strong: #1e1e1e;
  --panel: #09090b;
  --dot: #27272a;
  --btn-digit-bg: #18181b;
  --btn-action: #d4d4d8;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  min-height: 100dvh;
  overscroll-behavior: none;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.dot-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image: radial-gradient(circle, var(--dot) 1px, transparent 1px);
  background-size: 18px 18px;
  z-index: 0;
}

.app > *:not(.dot-bg) {
  position: relative;
  z-index: 1;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  gap: 8px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.red-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.brand-title {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 18px;
}

.icon-btn:hover {
  border-color: var(--accent);
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 0 12px 10px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 1;
  min-width: max-content;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 11px;
  font-family: var(--mono);
  cursor: pointer;
  white-space: nowrap;
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.panel.active {
  display: flex;
}

.display {
  padding: 16px 20px 8px;
  text-align: right;
}

.display-expression {
  font-family: var(--mono);
  font-size: clamp(18px, 5vw, 28px);
  word-break: break-all;
  min-height: 1.4em;
  opacity: 0.85;
}

.display-preview {
  font-family: var(--mono);
  font-size: clamp(14px, 3.5vw, 18px);
  color: var(--accent);
  min-height: 1.3em;
  margin-top: 4px;
}

.display-extra {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 10px;
  font-family: var(--mono);
  cursor: pointer;
  color: var(--text);
}

[data-theme="dark"] .badge,
[data-theme="dark"] .badge #angleLabel {
  color: #ffffff;
}

.badge .red-dot {
  width: 6px;
  height: 6px;
}

.hint {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-muted);
  text-align: right;
  margin-top: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  line-height: 1.3;
}

[data-theme="dark"] .hint {
  color: #e4e4e7;
  background: #18181b;
}

.keypad-wrap {
  flex: 1;
  background: var(--panel);
  border-top: 1px solid var(--border-strong);
  border-radius: 28px 28px 0 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  min-height: 280px;
}

.keypad-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.keypad-row.scientific {
  grid-template-columns: repeat(4, 1fr);
}

.calc-btn {
  border: 1px solid var(--border);
  border-radius: 14px;
  min-height: 52px;
  font-size: 18px;
  font-family: var(--mono);
  cursor: pointer;
  background: var(--btn-digit-bg);
  color: var(--text);
  transition: transform 0.05s ease;
}

.calc-btn:active {
  transform: scale(0.96);
}

.calc-btn.operator {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.calc-btn.action {
  background: transparent;
  color: var(--btn-action);
}

.calc-btn.advanced {
  font-size: 13px;
  color: var(--text-muted);
}

.calc-btn.equals {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.converter {
  padding: 12px 16px 24px;
  overflow-y: auto;
}

.field-label {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 6px;
}

.field-block {
  margin-bottom: 16px;
}

select.select-btn {
  appearance: none;
  cursor: pointer;
}

.select-btn,
.input-field {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 12px 14px;
  font-size: 15px;
  font-family: var(--mono);
}

.select-btn {
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.select-btn small {
  color: var(--text-muted);
  font-size: 11px;
}

.input-field {
  outline: none;
}

.input-field:focus {
  border-color: var(--accent);
}

.swap-row {
  display: flex;
  justify-content: center;
  margin: 4px 0 16px;
}

.swap-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--accent);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
}

.info-text {
  font-size: 11px;
  color: var(--text-muted);
  white-space: pre-line;
  line-height: 1.5;
  margin: 8px 0 12px;
}

.text-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  width: 100%;
}

.text-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status {
  font-size: 12px;
  color: var(--accent);
  margin-top: 8px;
}

.status.error {
  color: #ef4444;
}

.status.warning {
  color: #f59e0b;
}

.offline-indicator {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: #f59e0b;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  position: sticky;
  top: 0;
  z-index: 50;
}

.offline-indicator.visible {
  display: flex;
}

.update-banner {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 16px;
  background: #10b981;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  position: sticky;
  top: 0;
  z-index: 51;
}

.update-banner.visible {
  display: flex;
}

.update-btn {
  background: rgba(255, 255, 255, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  padding: 6px 14px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.update-btn:hover {
  background: rgba(255, 255, 255, 0.4);
}

.footer {
  padding: 8px 16px 16px;
  text-align: center;
}

.attribution {
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  line-height: 1.4;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.overlay.open {
  display: flex;
}

.modal {
  width: min(420px, 100%);
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 20px;
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.modal p {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

.modal-section {
  margin: 16px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
}

.modal-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-section ol {
  margin: 0;
  padding-left: 18px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
}

.modal-section li + li {
  margin-top: 8px;
}

.option-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.primary-btn,
.secondary-btn {
  flex: 1;
  border-radius: 12px;
  padding: 12px;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid var(--border);
}

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

.secondary-btn {
  background: transparent;
  color: var(--text);
}

.search-input {
  width: 100%;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  color: var(--text);
}

.list {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.list-item {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 12px 14px;
  cursor: pointer;
}

.list-item:last-child {
  border-bottom: none;
}

.list-item:hover,
.list-item:focus {
  background: var(--surface-2);
}

.list-item strong {
  color: var(--accent);
  margin-right: 8px;
}

.list-item small {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 2px;
}

.store-links {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.store-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 12px;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid var(--border);
}

.store-btn.play {
  background: #01875f;
  border-color: #01875f;
  color: #fff;
}

.store-btn.rustore {
  background: #0077ff;
  border-color: #0077ff;
  color: #fff;
}

.hidden {
  display: none !important;
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 0.5s ease;
}

.splash.hide {
  opacity: 0;
  pointer-events: none;
}

.splash-title {
  font-family: var(--mono);
  font-size: 22px;
  letter-spacing: 0.12em;
  font-weight: 700;
}

.splash-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.5s ease-in-out infinite;
}

@media (min-width: 481px) {
  .app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

@media (min-width: 768px) {
  .app {
    max-width: 720px;
  }
}

@media (min-width: 1024px) {
  .app {
    max-width: 960px;
  }
  
  .home-screen {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: auto auto 1fr;
    gap: 16px;
  }
  
  .home-title {
    grid-column: 1 / -1;
  }
  
  .home-card {
    margin-bottom: 0;
  }
  
  .copyright-block {
    grid-column: 1 / -1;
    order: 3;
  }
}

@media (display-mode: standalone) {
  .hide-standalone {
    display: none !important;
  }
}

.home-screen {
  padding: 8px 16px 24px;
  overflow-y: auto;
  flex: 1;
}

.home-title {
  margin: 0 0 16px;
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
}

@media (min-width: 1024px) {
  .home-title {
    order: 1;
  }
}

.home-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  padding: 16px;
  margin-bottom: 16px;
}

@media (min-width: 1024px) {
  .home-card {
    order: 2;
  }
}

.home-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.home-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.home-chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12px;
  font-family: var(--mono);
  cursor: pointer;
}

.home-chip:hover,
.home-chip:focus {
  border-color: var(--accent);
  color: var(--accent);
}

.copyright-block {
  margin-top: 0;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.6;
}

.desktop-only {
  display: none;
}

@media (min-width: 1024px) {
  .copyright-block {
    margin-bottom: 0;
    order: 3;
  }
  
  .desktop-only {
    display: block;
  }
  
  .copyright-block:not(.desktop-only) {
    display: none;
  }
}

.copyright-block strong {
  color: var(--text);
}

.copyright-block .line {
  display: block;
  margin-bottom: 4px;
}

.copyright-block .line:last-child {
  margin-bottom: 0;
}

.form-modal {
  max-height: 90dvh;
  overflow-y: auto;
}

.form-modal h2 {
  margin-top: 0;
}

.form-field {
  margin-bottom: 12px;
}

.form-field label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 12px;
}

.formula-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.formula-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  padding: 12px;
  cursor: pointer;
  color: var(--text);
}

.formula-item.selected {
  border-color: var(--accent);
  background: rgba(255, 48, 48, 0.08);
}

.formula-name {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.formula-expr {
  display: block;
  font-family: var(--mono);
  font-size: 13px;
}

.form-result {
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.form-dynamic {
  margin-top: 8px;
}
