:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --text: #1c2733;
  --sub: #697583;
  --line: #c7d0db;
  --accent: #2f8f63;
  --accent-soft: #e5f4ed;
  --shadow: 0 1px 5px rgba(31,45,61,.10);
}

[data-theme="dark"] {
  --bg: #000000;
  --card: #1c1c1e;
  --text: #ffffff;
  --sub: #98989f;
  --line: #38383a;
  --accent: #3dd68c;
  --accent-soft: #0d3b1e;
  --shadow: none;
}

[data-theme="high-contrast"] {
  --bg: #000;
  --card: #111;
  --text: #fff;
  --sub: #ffff00;
  --line: #fff;
  --accent: #ffff00;
  --accent-soft: #222;
  --shadow: none;
}

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

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: linear-gradient(180deg, #dce3eb 0%, #eef2f6 48%, #e3e9ef 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

[data-theme="dark"] body,
[data-theme="high-contrast"] body {
  background: #000;
}

button, input { font: inherit; max-width: 100%; min-width: 0; }
button { cursor: pointer; }

#app {
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px calc(env(safe-area-inset-bottom, 0px) + 16px);
  overflow-x: hidden;
}

/* Header */
.app-header { margin-bottom: 8px; }

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 2px 8px;
}

h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  line-height: 1.15;
}

.sub {
  font-size: 0.72rem;
  color: var(--sub);
  margin-top: 1px;
}

.status-row { display: flex; align-items: center; gap: 6px; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #45a66f;
  box-shadow: 0 0 0 3px #dff1e7;
}
.status-dot.off { background: #c5221f; box-shadow: 0 0 0 3px #fde8e8; }
.status-dot.warn { background: #9a6700; box-shadow: 0 0 0 3px #fff6e0; }

[data-theme="dark"] .status-dot { box-shadow: 0 0 0 3px #0d3b1e; }
[data-theme="dark"] .status-dot.off { box-shadow: 0 0 0 3px #4a1515; }

.refresh-btn {
  border: none;
  background: transparent;
  font-size: 1.1rem;
  color: var(--sub);
  padding: 2px 4px;
}

/* Place bar */
.place-bar, .place-editor, .custom-search {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.place-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  min-height: 48px;
}

.place-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.pin {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 16px;
  flex: none;
}

.place-text { min-width: 0; flex: 1; overflow: hidden; }
.place-label { display: block; font-size: 0.68rem; color: var(--sub); line-height: 1.1; }
.place-text strong {
  display: block;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.change-btn {
  flex: none;
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  background: #edf2f6;
  color: #29445a;
}
[data-theme="dark"] .change-btn { background: #2c2c2e; color: #fff; }

/* Manual editor */
.place-editor {
  margin-top: 6px;
  padding: 10px;
}

.editor-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.editor-row input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
}

.set-btn {
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 0.85rem;
}

.editor-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.secondary {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #edf2f6;
  color: #40576b;
  font-size: 0.8rem;
}
[data-theme="dark"] .secondary { background: #2c2c2e; color: #fff; border-color: #444; }

.hint {
  font-size: 0.7rem;
  color: var(--sub);
  line-height: 1.3;
}

/* Categories */
.category-section { padding-top: 4px; }

.section-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--sub);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin: 8px 2px 6px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

/* Glassy category buttons (inspired by your repo) */
.cat-btn {
  position: relative;
  isolation: isolate;
  min-height: 52px;
  padding: 10px 11px;
  border: 1px solid rgba(170, 188, 204, 0.55);
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.2;
  overflow: hidden;
  /* Glass */
  background-color: rgba(255, 255, 255, 0.55);
  background-image: linear-gradient(135deg, rgba(255,255,255,.75), rgba(255,255,255,.25));
  -webkit-backdrop-filter: blur(12px) saturate(130%);
  backdrop-filter: blur(12px) saturate(130%);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.9),
    0 2px 6px rgba(42,60,78,.08);
  transition: transform 0.1s;
}

.cat-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(105deg, rgba(255,255,255,.4), transparent 45%, rgba(255,255,255,.15));
  z-index: -1;
}

.cat-btn:active {
  transform: scale(0.97);
}

.cat-btn .emoji {
  font-size: 1.25rem;
  flex-shrink: 0;
}

/* Pastel glass tints */
.cat-btn:nth-child(6n+1) {
  background-color: rgba(226, 242, 253, 0.6);
  background-image: linear-gradient(135deg, rgba(255,255,255,.7), rgba(218,239,252,.45));
}
.cat-btn:nth-child(6n+2) {
  background-color: rgba(252, 232, 232, 0.6);
  background-image: linear-gradient(135deg, rgba(255,255,255,.7), rgba(252,220,220,.45));
}
.cat-btn:nth-child(6n+3) {
  background-color: rgba(224, 245, 235, 0.6);
  background-image: linear-gradient(135deg, rgba(255,255,255,.7), rgba(215,241,228,.45));
}
.cat-btn:nth-child(6n+4) {
  background-color: rgba(249, 239, 216, 0.6);
  background-image: linear-gradient(135deg, rgba(255,255,255,.7), rgba(247,232,198,.45));
}
.cat-btn:nth-child(6n+5) {
  background-color: rgba(243, 232, 253, 0.6);
  background-image: linear-gradient(135deg, rgba(255,255,255,.7), rgba(234,224,249,.45));
}
.cat-btn:nth-child(6n+6) {
  background-color: rgba(230, 247, 250, 0.6);
  background-image: linear-gradient(135deg, rgba(255,255,255,.7), rgba(222,232,246,.45));
}

[data-theme="dark"] .cat-btn {
  background: rgba(44, 44, 46, 0.9) !important;
  border-color: rgba(255,255,255,0.12) !important;
  color: #fff;
  box-shadow: none;
}
[data-theme="dark"] .cat-btn::before { display: none; }

[data-theme="high-contrast"] .cat-btn {
  background: #1a1a1a !important;
  border: 1px solid #fff !important;
  color: #fff;
}

/* Custom search */
.custom-search {
  margin-top: 14px;
  padding: 10px 12px;
}

.custom-row {
  display: flex;
  gap: 6px;
}

.custom-row input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
}

.custom-row button {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-size: 1.2rem;
  display: grid;
  place-items: center;
}

.custom-examples {
  margin-top: 6px;
  font-size: 0.7rem;
  color: var(--sub);
  line-height: 1.3;
}

/* Theme buttons */
.theme-bar {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 14px;
  margin-bottom: 4px;
}

.theme-btn {
  padding: 6px 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 0.75rem;
}

/* Footer */
footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 2px 4px;
  color: var(--sub);
  font-size: 0.72rem;
}

footer button {
  border: none;
  background: transparent;
  color: #456276;
  font-size: 0.78rem;
  padding: 2px 6px;
}
[data-theme="dark"] footer button { color: #aaa; }

/* Offline banner */
.offline-banner {
  background: #ff3b30;
  color: white;
  text-align: center;
  padding: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  display: none;
}
.offline-banner.show { display: block; }

.hidden { display: none !important; }
