* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font: 16px/1.35 ui-sans-serif, system-ui, sans-serif;
  color: #1c2430;
  background: #d5dde3;
}

#map { position: fixed; inset: 0; }

#panel {
  position: fixed;
  z-index: 1100;
  top: 12px;
  bottom: auto;
  left: 12px;
  right: auto;
  width: 312px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  padding: 12px 12px 10px;
  border: 1px solid rgba(23, 40, 58, 0.14);
  border-radius: 14px;
  background: rgba(247, 244, 238, 0.96);
  box-shadow: 0 10px 30px rgba(20, 32, 48, 0.16);
}

#panel-toggle { display: none; }

#panel section + section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(23, 40, 58, 0.1);
}

h2 {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.08em;
}

.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
  padding: 3px;
  border-radius: 10px;
  background: rgba(23, 58, 94, 0.08);
}

.seg button {
  flex: 1 1 40%;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  padding: 8px 4px;
}

.seg button[aria-pressed="true"] {
  background: #173a5e;
  color: #fff;
}

.wide {
  width: 100%;
  min-height: 42px;
  margin-top: 6px;
}

.grid-row { display: block; }

#home {
  width: 100%;
  min-height: 42px;
  margin-top: 6px;
}

button, input { font: inherit; }

button {
  cursor: pointer;
  border: 1px solid #c5ced6;
  border-radius: 8px;
  background: #fff;
  color: #1c2430;
  padding: 8px 10px;
}

button:disabled { cursor: default; opacity: 0.45; }

#find { display: flex; flex-direction: column; gap: 6px; }

.find-row button {
  flex: 1;
  min-height: 42px;
  white-space: nowrap;
}

.mgrs {
  min-height: 0;
  margin: 2px 0;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.15rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.mgrs:empty { display: none; }

.ez {
  margin: 0;
  color: #0b4f8a;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.25rem;
  font-weight: 750;
}

.ez[hidden] { display: none; }

.latlon {
  color: #3d4c5c;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.75rem;
}

.point-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.point-actions[hidden] { display: none; }

.point-actions button,
.point-actions a {
  flex: 1;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #c5ced6;
  border-radius: 8px;
  background: #fff;
  color: #1c2430;
  padding: 8px 10px;
  font-weight: 650;
  text-decoration: none;
}

.status {
  min-height: 1.2em;
  margin: 6px 0 0;
  color: #5c6b7a;
  font-size: 0.82rem;
}

.status:empty { display: none; }

.status.error { color: #8a2b2b; }

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

input {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  border: 1px solid #c5ced6;
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}

.mgrs-canvas {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}

.cell-label-wrap {
  background: none !important;
  border: 0 !important;
}

.cell-label {
  display: inline-block;
  transform: translate(-50%, -50%);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 750;
  white-space: nowrap;
  text-shadow:
    -1px 0 #fff, 1px 0 #fff, 0 -1px #fff, 0 1px #fff,
    0 0 4px #fff;
  pointer-events: none;
}

.cell-label.sq-100 { color: #0c7a32; font-size: 16px; letter-spacing: 0.04em; }
.cell-label.sq-fine { color: #d40000; font-size: 13px; }
.cell-label.sq-ez { color: #0b4f8a; font-size: 14px; }

@media (max-width: 799px) {
  #panel {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    max-height: none;
    padding: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    pointer-events: none;
  }

  #grid-block,
  #panel-toggle,
  #panel-body {
    pointer-events: auto;
  }

  #grid-block {
    position: absolute;
    top: calc(8px + env(safe-area-inset-top));
    left: 8px;
    right: 56px;
    padding: 4px;
    border: 1px solid rgba(23, 40, 58, 0.14);
    border-radius: 12px;
    background: rgba(247, 244, 238, 0.96);
    box-shadow: 0 8px 20px rgba(20, 32, 48, 0.14);
  }

  #grid-block h2 { display: none; }

  .grid-row {
    display: flex;
    align-items: center;
    gap: 4px;
  }

  #grid-block .seg {
    flex: 1;
    margin: 0;
    padding: 2px;
  }

  #grid-block .seg button {
    flex: 1 1 auto;
    min-height: 34px;
    padding: 4px 2px;
    font-size: 0.72rem;
  }

  #home {
    width: auto;
    min-height: 34px;
    margin: 0;
    padding: 4px 8px;
    font-size: 0.72rem;
  }

  #panel-toggle {
    display: flex;
    position: absolute;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: 8px;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: auto;
    min-height: 44px;
    border: 1px solid rgba(23, 40, 58, 0.14);
    border-radius: 12px;
    background: rgba(247, 244, 238, 0.96);
    box-shadow: 0 8px 20px rgba(20, 32, 48, 0.14);
    padding: 8px 12px;
    font-weight: 650;
    text-align: left;
  }

  #panel.is-open #panel-toggle { border-radius: 12px; }

  #bar-mgrs {
    min-width: 0;
    overflow: hidden;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.82rem;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #panel-body {
    display: none;
    position: absolute;
    right: 8px;
    bottom: calc(60px + env(safe-area-inset-bottom));
    left: 8px;
    max-height: 42vh;
    overflow: auto;
    padding: 8px 10px 10px;
    border: 1px solid rgba(23, 40, 58, 0.14);
    border-radius: 12px;
    background: rgba(247, 244, 238, 0.96);
    box-shadow: 0 8px 20px rgba(20, 32, 48, 0.14);
  }

  #panel.is-open #panel-body { display: block; }

  #panel section + section {
    margin-top: 8px;
    padding-top: 8px;
  }

  .find-row button,
  .point-actions button,
  .point-actions a {
    min-height: 36px;
    padding: 6px 8px;
  }

  input {
    min-height: 40px;
    padding: 8px 10px;
    font-size: 0.95rem;
  }

  .mgrs { font-size: 1rem; }
  .point-actions { margin-top: 8px; }
}

@media (min-width: 800px) {
  #panel-body {
    display: block;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(23, 40, 58, 0.1);
  }
}
