:root {
  --bg: #0a0e17;
  --surface: #111827;
  --surface2: #1a2332;
  --border: #1e293b;
  --primary: #0f3460;
  --accent: #3b82f6;
  --accent2: #22d3ee;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  line-height: 1.45;
}

body {
  padding-top: var(--safe-top);
  padding-bottom: calc(70px + var(--safe-bottom));
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(180deg, var(--surface) 0%, rgba(17,24,39,0.95) 100%);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-header h1 span {
  color: var(--accent2);
  font-weight: 400;
  font-size: 0.75rem;
}

.status-pill {
  font-size: 0.7rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-pill.online::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.status-pill.offline::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warning);
}

/* Main content */
.main {
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
}

/* Tool grid */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
  user-select: none;
}

.tool-card:active {
  transform: scale(0.96);
}

.tool-card:hover, .tool-card.active {
  border-color: var(--accent);
  background: var(--surface2);
}

.tool-card .icon {
  font-size: 1.75rem;
  margin-bottom: 8px;
  display: block;
}

.tool-card .label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
}

.tool-card .sub {
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 2px;
}

/* Tool panel (hidden by default) */
.tool-panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 12px;
  animation: fadeIn 0.2s ease;
}

.tool-panel.visible {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  font-size: 1rem;
  font-weight: 700;
}

.btn-back {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
}

.btn-back:active {
  background: var(--surface2);
}

/* Form elements */
label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 500;
}

input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

textarea {
  min-height: 80px;
  resize: vertical;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.85rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 11px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s, transform 0.1s;
}

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

.btn:hover {
  background: #1a4a7a;
}

.btn-secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn-row .btn {
  flex: 1;
}

/* Result box */
.result {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-top: 12px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.85rem;
  word-break: break-all;
  white-space: pre-wrap;
  max-height: 280px;
  overflow-y: auto;
}

.result.empty {
  color: var(--muted);
  font-style: italic;
}

.result .row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

.result .row:last-child {
  border-bottom: none;
}

.result .key {
  color: var(--muted);
  flex-shrink: 0;
  margin-right: 12px;
}

.result .val {
  color: var(--accent2);
  text-align: right;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(8px + var(--safe-bottom));
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--muted);
  font-size: 0.65rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 12px;
  min-width: 64px;
}

.nav-item.active {
  color: var(--accent2);
}

.nav-item .nav-icon {
  font-size: 1.25rem;
}

/* Clock specific */
.clock-display {
  text-align: center;
  padding: 20px 0;
}

.clock-zulu {
  font-size: 2.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  color: var(--accent2);
}

.clock-dtg {
  font-size: 1.1rem;
  color: var(--text);
  margin-top: 8px;
  font-family: ui-monospace, monospace;
}

.clock-local {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 6px;
}

/* Phonetic table */
.phonetic-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  font-size: 0.8rem;
}

.phonetic-item {
  background: var(--bg);
  border-radius: 6px;
  padding: 6px 4px;
  text-align: center;
}

.phonetic-item .letter {
  font-weight: 700;
  color: var(--accent2);
}

/* QR */
#qrcode {
  display: flex;
  justify-content: center;
  padding: 12px;
  background: white;
  border-radius: 8px;
  margin-top: 12px;
}

/* Section title */
.section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 16px 0 10px;
  font-weight: 600;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.85rem;
  opacity: 0;
  transition: all 0.25s;
  z-index: 200;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* About */
.about-text {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.6;
}

.about-text a {
  color: var(--accent2);
}

/* Utility */
.hidden { display: none !important; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.text-center { text-align: center; }
.small { font-size: 0.75rem; color: var(--muted); }
