@font-face {
  font-family: "Semaphore";
  src: url("../assets/fonts/EnigmailedSemaphore-Regular.ttf") format("truetype");
  font-display: swap;
}

/* ── Layout ── */
html, body { height: 100%; margin: 0; }

header nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-block: 0.5rem;
}

header nav .nav-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

header nav select {
  margin: 0;
  width: auto;
  padding: 0.3rem 0.4rem;
  font-size: 1rem;
  height: auto;
}

main.container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-block: 0.75rem;
  /* leave room for keyboard */
  padding-bottom: calc(0.75rem + var(--keyboard-height, 0px));
}

/* ── IO Areas ── */
.io-area { display: flex; flex-direction: column; gap: 0.25rem; }

.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field-header label { margin: 0; font-weight: 600; }

.field-actions { display: flex; gap: 0.25rem; }

textarea {
  resize: none;
  font-size: 1rem;
  line-height: 1.5;
  transition: font-family 0.1s;
}

textarea.semaphore-font,
.semaphore-font { font-family: "Semaphore", sans-serif; }

/* ── Direction bar ── */
.direction-bar {
  display: flex;
  justify-content: center;
}

.switch-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

.switch-label input[type="checkbox"] { margin: 0; }

/* ── Icon buttons ── */
.icon-btn {
  padding: 0.3rem 0.4rem;
  font-size: 1.1rem;
  line-height: 1;
  background: transparent;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:active { transform: scale(0.9); }

/* Button action feedback */
.icon-btn.active {
  background: var(--pico-primary);
  border-color: transparent;
  color: var(--pico-primary-inverse);
  animation: btn-pop 0.2s ease;
}

@keyframes btn-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes btn-glow {
  0%, 100% { box-shadow: 0 0 0 0px var(--pico-primary); }
  50%      { box-shadow: 0 0 0 4px var(--pico-primary); }
}

.icon-btn.processing {
  animation: btn-glow 1s ease-in-out infinite;
}

/* PWA mode adjustments */
@media (display-mode: standalone) {
  #keyboard-container {
    padding-bottom: 48px !important;
    border-bottom: none !important;
  }
}

/* ── Custom Keyboard ── */
#keyboard-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--pico-card-background-color);
  border-top: 1px solid var(--pico-muted-border-color);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  padding: 0.5rem;
  display: none;
}

#keyboard-container.visible { display: block; }

.keyboard-grid {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: 480px;
  margin: 0 auto;
}

.keyboard-row {
  display: flex;
  gap: 0.2rem;
}

.key {
  flex: 1;
  padding: 0.4rem 0.25rem;
  font-size: 1rem;
  text-align: center;
  background: var(--pico-secondary-background);
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s, transform 0.08s;
  touch-action: manipulation;
  margin-bottom: 0 !important;
}

.key:active { transform: scale(0.92); background: var(--pico-primary-background); }
.key:hover  { background: var(--pico-primary); color: var(--pico-primary-inverse); }

.key.wide   { flex: 2; }
.key.wider  { flex: 3; }

/* Braille dot keys */
.key.dot-key { font-size: 1.4rem; }
.key.dot-key.active { background: var(--pico-primary); color: var(--pico-primary-inverse); }

.key.dot-key > span::after {
  display: inline-block;
  transform: scale(1.4);
  vertical-align: middle;
}
.key.dot-key:not(.active) > span::after { content: "○"; }
.key.dot-key.active > span::after       { content: "●"; }

/* Semaphore keys use the font */
.key.semaphore-key { font-family: "Semaphore", sans-serif; font-size: 1.6rem; padding: 0.3rem; }

/* ── Info dialog ── */
#info-map {
  max-height: 40vh;
  overflow-y: auto;
}

#info-map table {
  width: 100%;
  font-size: 0.85rem;
}

#info-map td.semaphore-font {
  font-size: 1.6rem;
  line-height: 1;
}

/* ── Image crop dialog ── */
.crop-wrap { position: relative; max-height: 60vh; overflow: hidden; }
.crop-wrap img { max-width: 100%; display: block; }
#ocr-status { text-align: center; padding: 1rem; }

/* ── Anagram results ── */
#output.anagram-output { font-size: 0.9rem; }

/* ── Accessibility ── */
button:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--pico-primary);
  outline-offset: -2px;
}

/* ── Scrollbar ── */
:root {
  scrollbar-color: var(--pico-primary) var(--pico-card-background-color);
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--pico-card-background-color); }
::-webkit-scrollbar-thumb {
  background-color: var(--pico-primary);
  border-radius: 5px;
  border: 2px solid var(--pico-card-background-color);
}

/* ── Cropper.js colors ── */
.cropper-view-box {
  outline: 1px solid var(--primary);
  outline-color: var(--primary);
}

.cropper-point,
.cropper-line {
  background-color: var(--primary);
}

.cropper-dashed {
  border-color: var(--primary);
}

/* ── Print ── */
@media print {
  header, #keyboard-container, .field-actions { display: none !important; }
}
