/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 16px; }
body { display: flex; flex-direction: column; height: 100dvh; background: #f5f5f5; overflow: hidden; }

/* === WELCOME MODAL === */
.welcome-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.welcome-overlay.hidden { display: none; }
.welcome-modal {
  background: #fff; border-radius: 16px; max-width: 440px; width: 100%;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  overflow: hidden; animation: welcomeIn .3s ease;
}
@keyframes welcomeIn {
  from { transform: scale(.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.welcome-header {
  background: linear-gradient(135deg, #1565C0, #0D47A1);
  color: #fff; padding: 24px; text-align: center;
}
.welcome-header h2 { font-size: 1.3rem; font-weight: 700; }
.welcome-body { padding: 20px 24px 24px; }
.welcome-body p { margin-bottom: 12px; color: #555; font-size: .95rem; line-height: 1.5; }
.welcome-body h3 { font-size: 1rem; color: #333; margin-bottom: 8px; }
.welcome-body ul { list-style: none; margin-bottom: 16px; }
.welcome-body li {
  padding: 6px 0; padding-left: 24px; position: relative;
  color: #444; font-size: .9rem; line-height: 1.4;
}
.welcome-body li::before {
  content: '✓'; position: absolute; left: 0; color: #4CAF50; font-weight: 700;
}
#welcome-pictograms {
  background: #E3F2FD; padding: 10px 14px; border-radius: 8px;
  text-align: center; font-weight: 600; color: #1565C0; margin-bottom: 16px;
}
.welcome-btn {
  display: block; width: 100%; padding: 14px;
  background: #1565C0; color: #fff; border: none; border-radius: 10px;
  font-size: 1.1rem; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.welcome-btn:hover { background: #0D47A1; }
.welcome-btn:active { background: #0A3D91; }

/* === EXAMPLE SENTENCES === */
.example-sentences {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 4px;
  background: var(--board-bg, #fff);
}
.example-sentences.hidden { display: none; }
.example-btn {
  padding: 6px 12px; border-radius: 16px;
  border: 1px solid #ddd; background: #f9f9f9; color: #666;
  font-size: .8rem; cursor: pointer; transition: all .15s;
  white-space: nowrap;
}
.example-btn:hover { background: #E3F2FD; border-color: #1565C0; color: #1565C0; }
.example-label { font-size: .75rem; color: #aaa; margin-right: 4px; }

/* === HEADER === */
#app-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: #1565C0; color: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,.2); z-index: 10;
}
.header-left, .header-right { display: flex; align-items: center; gap: 8px; }
#app-header h1 { font-size: 1.1rem; font-weight: 600; white-space: nowrap; }
.icon-btn {
  background: none; border: none; color: inherit; font-size: 1.3rem;
  cursor: pointer; padding: 6px; border-radius: 6px; line-height: 1;
}
.icon-btn:hover { background: rgba(255,255,255,.15); }
.icon-btn:active { background: rgba(255,255,255,.25); }

/* === SYMBOL BOARD === */
#symbol-board {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 16px; background: var(--board-bg, #fff);
}
.symbols-grid {
  display: flex; flex-wrap: wrap; gap: 8px;
  align-items: flex-start; justify-content: flex-start;
}
.symbol-card {
  display: flex; flex-direction: column; align-items: center;
  width: var(--symbol-size, 120px); cursor: pointer;
  padding: 6px; border-radius: 8px;
  transition: background .15s, transform .1s;
  user-select: none;
}
.symbol-card:hover { background: rgba(0,0,0,.05); }
.symbol-card:active { transform: scale(.95); }
.symbol-card.bordered { border: 2px solid #ddd; }
.symbol-card.text-above .symbol-label { order: -1; }

.symbol-img {
  width: calc(var(--symbol-size, 120px) - 16px);
  height: calc(var(--symbol-size, 120px) - 16px);
  object-fit: contain;
}
.symbol-placeholder {
  width: calc(var(--symbol-size, 120px) - 16px);
  height: calc(var(--symbol-size, 120px) - 16px);
  display: flex; align-items: center; justify-content: center;
  background: #f0f0f0; border-radius: 6px; border: 2px dashed #ccc;
  font-size: calc(var(--symbol-size, 120px) * 0.25);
  color: #999;
}
.symbol-label {
  margin-top: 4px; text-align: center; font-weight: 600;
  font-size: var(--label-size, 16px); color: #333;
  word-break: break-word; max-width: 100%;
}
.symbol-label.hidden { display: none; }

/* Newline separator */
.symbol-newline {
  flex-basis: 100%; height: 0;
}

.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; text-align: center;
  color: #888; gap: 8px;
}
.empty-state.hidden { display: none; }
.empty-icon { font-size: 4rem; opacity: .5; }
.empty-hint { font-size: .85rem; color: #aaa; }

/* === INPUT AREA === */
#input-area {
  border-top: 1px solid #ddd; background: #fff;
  padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.input-wrapper { display: flex; gap: 8px; align-items: flex-end; }
#text-input {
  flex: 1; border: 2px solid #1565C0; border-radius: 10px;
  padding: 10px 14px; font-size: 1.1rem; resize: none;
  outline: none; font-family: inherit;
}
#text-input:focus { border-color: #0D47A1; box-shadow: 0 0 0 3px rgba(21,101,192,.2); }
.speak-btn {
  background: #4CAF50; color: #fff; border: none;
  border-radius: 10px; padding: 10px 14px; font-size: 1.3rem;
  cursor: pointer; line-height: 1;
}
.speak-btn:hover { background: #43A047; }
.speak-btn:active { background: #388E3C; }

.input-toolbar {
  display: flex; gap: 6px; margin-top: 8px; overflow-x: auto;
  padding-bottom: 2px; -webkit-overflow-scrolling: touch;
}
.quick-btn {
  white-space: nowrap; padding: 6px 14px; border-radius: 20px;
  border: 2px solid #1565C0; background: #E3F2FD; color: #1565C0;
  font-size: .9rem; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.quick-btn:hover { background: #BBDEFB; }
.quick-btn:active { background: #90CAF9; }

/* === PANELS === */
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(400px, 90vw);
  background: #fff; z-index: 100; box-shadow: -4px 0 12px rgba(0,0,0,.15);
  display: flex; flex-direction: column;
  transform: translateX(0); transition: transform .25s ease;
}
.panel.hidden { transform: translateX(100%); pointer-events: none; }
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid #eee; background: #f9f9f9;
}
.panel-header h2 { font-size: 1.1rem; }
.panel-body { flex: 1; overflow-y: auto; padding: 16px; }
.setting { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid #f0f0f0; }
.setting span { font-size: .95rem; }
.setting select, .setting input[type=range] { max-width: 140px; }
.setting-section { margin-top: 16px; }
.setting-section h3 { font-size: .95rem; color: #666; margin-bottom: 8px; }

/* === SIDE MENU === */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90; transition: opacity .25s; }
.overlay.hidden { opacity: 0; pointer-events: none; }
.side-menu {
  position: fixed; top: 0; left: 0; bottom: 0; width: min(300px, 80vw);
  background: #fff; z-index: 100; box-shadow: 4px 0 12px rgba(0,0,0,.15);
  display: flex; flex-direction: column;
  transform: translateX(0); transition: transform .25s ease;
}
.side-menu.hidden { transform: translateX(-100%); pointer-events: none; }
.menu-header { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid #eee; }
.menu-header h2 { font-size: 1.1rem; }
.side-menu ul { list-style: none; flex: 1; overflow-y: auto; }
.side-menu li button, .side-menu li a.menu-link {
  display: block; width: 100%; text-align: left; padding: 14px 20px;
  border: none; background: none; font-size: 1rem; cursor: pointer;
  color: #333; text-decoration: none;
}
.side-menu li button:hover, .side-menu li a.menu-link:hover { background: #f5f5f5; }
.side-menu li hr { border: none; border-top: 1px solid #eee; margin: 4px 16px; }
.menu-footer { padding: 16px; border-top: 1px solid #eee; font-size: .8rem; color: #888; }
.menu-footer a { color: #1565C0; }
.license { margin-top: 4px; }

/* === SYMBOL PICKER === */
.picker {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-height: 60vh; background: #fff; z-index: 100;
  border-radius: 16px 16px 0 0; box-shadow: 0 -4px 12px rgba(0,0,0,.15);
  display: flex; flex-direction: column;
  transform: translateY(0); transition: transform .25s ease;
}
.picker.hidden { transform: translateY(100%); pointer-events: none; }
.picker-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid #eee; }
.picker-header h3 { font-size: 1rem; color: #666; }
.picker-grid {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 12px;
  overflow-y: auto; justify-content: flex-start;
}
.picker-item {
  width: 90px; display: flex; flex-direction: column; align-items: center;
  padding: 6px; border-radius: 8px; cursor: pointer; border: 2px solid transparent;
}
.picker-item:hover { border-color: #1565C0; background: #E3F2FD; }
.picker-item img { width: 70px; height: 70px; object-fit: contain; }
.picker-item span { font-size: .75rem; text-align: center; color: #666; margin-top: 2px; }

/* === SAVED SENTENCES === */
.saved-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px; border-bottom: 1px solid #f0f0f0; cursor: pointer;
}
.saved-item:hover { background: #f5f5f5; }
.saved-text { font-size: .95rem; flex: 1; }
.saved-delete { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: #999; padding: 4px; }
.saved-delete:hover { color: #e00; }

/* === PRINT === */
#print-header, #print-footer { display: none; }
#title-area { display: none; } /* Hide interactive title input in print — shown via print-header */

@media print {
  #app-header, #input-area, .side-menu, .panel, .overlay, .picker, #welcome-screen, #title-area { display: none !important; }
  body { height: auto; overflow: visible; }
  #symbol-board { overflow: visible; padding: 16px 0; }
  .symbols-grid { gap: 12px; }
  .symbol-card { break-inside: avoid; }

  /* Print header: title centered, timestamp top-right */
  #print-header {
    display: flex !important;
    justify-content: center;
    align-items: flex-start;
    position: relative;
    padding: 8px 16px 12px;
    border-bottom: 1px solid #ccc;
    margin-bottom: 8px;
  }
  .print-title-text {
    font-size: 1.4rem;
    font-weight: 700;
    text-align: center;
    flex: 1;
  }
  .print-timestamp {
    position: absolute;
    top: 8px;
    right: 16px;
    font-size: 0.8rem;
    color: #666;
    white-space: nowrap;
  }

  /* Print footer: bottom-left */
  #print-footer {
    display: block !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 16px;
    border-top: 1px solid #ccc;
  }
  .print-footer-text {
    font-size: 0.75rem;
    color: #888;
    text-align: left;
  }
}

/* Title area — visible on screen for input */
#title-area { display: block; padding: 8px 12px 0; background: var(--board-bg, #fff); }
#title-input {
  width: 100%; border: 1px dashed #ccc; border-radius: 6px;
  padding: 8px 12px; font-size: 1.1rem; font-weight: 700; text-align: center;
  font-family: inherit; outline: none; background: transparent;
}
#title-input:focus { border-color: #1565C0; border-style: solid; }
#title-input::placeholder { font-weight: 400; color: #aaa; }

/* === RESPONSIVE === */
@media (max-width: 480px) {
  #app-header h1 { font-size: .95rem; }
  .symbols-grid { gap: 4px; }
  .symbol-card { padding: 4px; }
}
