* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --ink: #f8f1e8;
  --muted: #cbbeb4;
  --panel: rgba(13, 13, 18, 0.72);
  --panel-strong: rgba(20, 18, 23, 0.88);
  --line: rgba(233, 186, 122, 0.46);
  --gold: #f5d36d;
  --copper: #c97f48;
  --teal: #6ee7d8;
  --rose: #dd7f86;
  --dark: #111116;
  --danger: #ff7a7a;
  --success: #8ee2a0;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background:
    linear-gradient(rgba(13, 13, 18, 0.26), rgba(13, 13, 18, 0.42)),
    radial-gradient(circle at 16% 12%, rgba(245, 211, 109, 0.2), transparent 28%),
    radial-gradient(circle at 82% 24%, rgba(110, 231, 216, 0.17), transparent 25%),
    linear-gradient(135deg, #15151d 0%, #2b1f22 42%, #17302e 100%);
  background-attachment: fixed;
}

body.mobile-device {
  font-size: 17px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body.mobile-device button,
body.mobile-device input,
body.mobile-device select {
  font-size: 17px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.026) 1px, transparent 1px),
    rgba(0, 0, 0, 0.58);
  background-size: 42px 42px;
}

.app-container {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 24px;
}

.header,
.section,
.footer {
  width: 100%;
  max-width: 1240px;
}

.header {
  margin-top: 8px;
}

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

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand-mark {
  width: 74px;
  height: 74px;
  border-radius: 18px;
  box-shadow: 0 0 28px rgba(245, 211, 109, 0.24);
}

.main-title {
  font-size: 46px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--ink);
  text-shadow: 0 0 24px rgba(245, 211, 109, 0.26);
}

.tagline {
  margin-top: 8px;
  color: var(--muted);
  font-size: 17px;
}

.time-display {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
  justify-content: flex-end;
  color: var(--gold);
  font-weight: 700;
}

.clock-icon {
  font-size: 22px;
}

.section {
  position: relative;
  padding: 24px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--copper);
  border-right: 4px solid var(--teal);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 20px 46px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(10px);
}

.section::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: rgba(255, 255, 255, 0.24);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.section-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: var(--gold);
  font-size: 25px;
  border: 1px solid rgba(245, 211, 109, 0.42);
  border-radius: 8px;
  background: rgba(245, 211, 109, 0.08);
}

.section-title {
  font-size: 26px;
  letter-spacing: 0;
}

.model-config {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin: -6px 0 20px;
}

.model-config[hidden] {
  display: none;
}

.model-label {
  color: var(--muted);
  font-weight: 800;
}

.model-select {
  min-width: 150px;
  min-height: 42px;
  border: 1px solid rgba(245, 211, 109, 0.42);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.42);
  font: inherit;
  font-weight: 800;
  padding: 0 14px;
}

.reader-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(360px, 1.1fr);
  gap: 22px;
}

.upload-panel,
.result-panel {
  min-width: 0;
}

.source-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.source-btn {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.09);
  font: inherit;
  font-weight: 800;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.source-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(110, 231, 216, 0.48);
  background: rgba(110, 231, 216, 0.1);
}

.source-btn-primary {
  color: #111116;
  background: linear-gradient(135deg, var(--teal), var(--gold));
  border-color: transparent;
}

.source-btn span {
  font-size: 18px;
}

.drop-zone {
  display: flex;
  min-height: 178px;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px dashed rgba(245, 211, 109, 0.56);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--ink);
  text-align: center;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--teal);
  background: rgba(110, 231, 216, 0.1);
  transform: translateY(-1px);
}

.drop-icon {
  font-size: 42px;
  color: var(--gold);
}

.drop-title {
  font-size: 20px;
  font-weight: 800;
}

.drop-detail {
  max-width: 340px;
  color: var(--muted);
  font-size: 14px;
}

.preview-frame {
  display: grid;
  position: relative;
  min-height: 260px;
  margin-top: 18px;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.36);
}

.preview-frame img {
  display: none;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
}

.preview-frame.has-image img {
  display: block;
}

.preview-frame.has-image .preview-empty {
  display: none;
}

.preview-empty {
  color: var(--muted);
  font-weight: 700;
}

.crop-panel {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid rgba(245, 211, 109, 0.3);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.38);
}

.crop-panel[hidden] {
  display: none;
}

.crop-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 5;
  max-height: 520px;
  overflow: hidden;
  border-radius: 8px;
  background: #050507;
}

.crop-viewport img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform-origin: center;
  user-select: none;
  pointer-events: none;
}

.crop-frame {
  position: absolute;
  inset: 12px;
  border: 2px solid rgba(245, 211, 109, 0.86);
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.22);
  pointer-events: none;
}

.crop-controls {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.crop-controls label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.crop-controls input {
  width: 100%;
  accent-color: var(--gold);
}

.crop-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-top: 14px;
}

.camera-panel {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid rgba(110, 231, 216, 0.28);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.38);
}

.camera-panel[hidden] {
  display: none;
}

.camera-panel video {
  display: block;
  width: 100%;
  max-height: 420px;
  border-radius: 8px;
  background: #050507;
  object-fit: contain;
}

.camera-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.camera-btn {
  min-height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.09);
  font: inherit;
  font-weight: 800;
}

.camera-btn-primary {
  color: #111116;
  background: linear-gradient(135deg, var(--teal), var(--gold));
  border-color: transparent;
}

.consent-row {
  margin-top: 18px;
}

.toggle-line {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.toggle-line input {
  width: 18px;
  height: 18px;
  accent-color: var(--copper);
  flex: 0 0 auto;
  margin-top: 1px;
}

.read-btn,
.ghost-btn {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.read-btn {
  display: flex;
  width: 100%;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
  color: #111116;
  background: linear-gradient(135deg, var(--gold), var(--copper));
  box-shadow: 0 12px 28px rgba(201, 127, 72, 0.26);
  font-size: 17px;
}

.read-btn:hover:not(:disabled),
.ghost-btn:hover {
  transform: translateY(-1px);
}

.read-btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  box-shadow: none;
}

.btn-icon {
  font-size: 20px;
}

.result-panel {
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 20px;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.result-header h3 {
  font-size: 24px;
}

#result-status {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.ghost-btn {
  min-width: 72px;
  min-height: 38px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.reading-card {
  min-height: 410px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.3);
  padding: 20px;
}

.reading-placeholder {
  display: grid;
  min-height: 360px;
  place-items: center;
  align-content: center;
  gap: 14px;
  color: var(--muted);
  text-align: center;
}

.placeholder-mark {
  color: var(--gold);
  font-size: 48px;
}

.reading-content {
  display: grid;
  gap: 18px;
}

.reading-overview {
  color: var(--ink);
  font-size: 18px;
  line-height: 1.55;
}

.reading-list {
  display: grid;
  gap: 12px;
}

.reading-list article {
  padding: 16px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.reading-list h4 {
  color: var(--gold);
  font-size: 16px;
  margin-bottom: 8px;
}

.reading-list p,
.reading-note {
  color: var(--muted);
  line-height: 1.5;
}

.reading-note {
  border-left: 3px solid var(--teal);
  padding-left: 12px;
  font-size: 15px;
}

.focus-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.focus-item {
  min-height: 126px;
  padding: 18px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.focus-item span {
  display: block;
  color: var(--gold);
  font-weight: 800;
  margin-bottom: 8px;
}

.focus-item p {
  color: var(--muted);
  line-height: 1.45;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.feature-panel {
  display: flex;
  min-height: 430px;
  flex-direction: column;
  gap: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.3);
  padding: 18px;
}

.feature-head h3 {
  color: var(--ink);
  font-size: 22px;
  margin-bottom: 6px;
}

.feature-head p {
  min-height: 40px;
  color: var(--muted);
  line-height: 1.4;
}

.feature-btn {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  color: #111116;
  background: linear-gradient(135deg, var(--gold), var(--copper));
  font: inherit;
  font-weight: 800;
}

.feature-btn:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.feature-result {
  flex: 1;
  overflow: auto;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 14px;
}

.feature-result p,
.feature-result li {
  color: var(--muted);
  line-height: 1.5;
}

.feature-result h4 {
  color: var(--gold);
  font-size: 15px;
  margin: 14px 0 6px;
}

.feature-result h4:first-child {
  margin-top: 0;
}

.compatibility-form {
  display: grid;
  gap: 10px;
}

.compatibility-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.compatibility-form input,
.compatibility-form select,
.chat-form input {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(245, 211, 109, 0.36);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.38);
  font: inherit;
  padding: 0 12px;
}

.chat-log {
  display: flex;
  min-height: 246px;
  max-height: 320px;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 12px;
}

.chat-message {
  width: fit-content;
  max-width: 92%;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  line-height: 1.45;
  background: rgba(255, 255, 255, 0.08);
}

.chat-message.user {
  align-self: flex-end;
  color: #111116;
  background: linear-gradient(135deg, var(--teal), var(--gold));
}

.chat-message.teller {
  align-self: flex-start;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 10px;
}

body.mobile-device .app-container {
  gap: 16px;
  padding: 14px;
}

body.mobile-device .header,
body.mobile-device .section,
body.mobile-device .footer {
  max-width: 100%;
}

body.mobile-device .header-content,
body.mobile-device .reader-grid,
body.mobile-device .focus-grid,
body.mobile-device .feature-grid {
  display: grid;
  grid-template-columns: 1fr;
}

body.mobile-device .brand-lockup {
  align-items: flex-start;
  gap: 12px;
}

body.mobile-device .brand-mark {
  width: 58px;
  height: 58px;
  border-radius: 14px;
}

body.mobile-device .main-title {
  font-size: 34px;
}

body.mobile-device .tagline {
  font-size: 16px;
  line-height: 1.4;
}

body.mobile-device .time-display {
  min-width: 0;
  justify-content: flex-start;
  font-size: 15px;
}

body.mobile-device .section {
  padding: 16px;
  border-left-width: 3px;
  border-right-width: 3px;
}

body.mobile-device .section-header {
  gap: 10px;
  margin-bottom: 16px;
}

body.mobile-device .section-icon {
  width: 34px;
  height: 34px;
  font-size: 22px;
}

body.mobile-device .section-title {
  font-size: 23px;
}

body.mobile-device .model-config,
body.mobile-device .source-actions,
body.mobile-device .camera-actions,
body.mobile-device .crop-actions,
body.mobile-device .chat-form {
  grid-template-columns: 1fr;
}

body.mobile-device .model-config {
  display: grid;
  align-items: stretch;
  justify-content: stretch;
}

body.mobile-device .source-btn,
body.mobile-device .camera-btn,
body.mobile-device .feature-btn,
body.mobile-device .read-btn,
body.mobile-device .ghost-btn,
body.mobile-device .model-select,
body.mobile-device .compatibility-form input,
body.mobile-device .compatibility-form select,
body.mobile-device .chat-form input {
  min-height: 50px;
}

body.mobile-device .drop-zone {
  min-height: 150px;
  padding: 18px;
}

body.mobile-device .drop-title {
  font-size: 19px;
}

body.mobile-device .drop-detail,
body.mobile-device .toggle-line,
body.mobile-device #result-status,
body.mobile-device .feature-head p,
body.mobile-device .feature-result p,
body.mobile-device .feature-result li,
body.mobile-device .reading-list p,
body.mobile-device .reading-note {
  font-size: 16px;
  line-height: 1.55;
}

body.mobile-device .preview-frame {
  min-height: 220px;
}

body.mobile-device .crop-viewport {
  aspect-ratio: 3 / 4;
  max-height: none;
}

body.mobile-device .crop-controls {
  gap: 16px;
}

body.mobile-device .crop-controls label {
  font-size: 16px;
}

body.mobile-device .crop-controls input[type="range"] {
  min-height: 36px;
}

body.mobile-device .result-panel,
body.mobile-device .reading-card,
body.mobile-device .feature-panel,
body.mobile-device .feature-result,
body.mobile-device .chat-log {
  padding: 16px;
}

body.mobile-device .result-header,
body.mobile-device .history-item {
  align-items: flex-start;
  flex-direction: column;
}

body.mobile-device .reading-card {
  min-height: 0;
}

body.mobile-device .reading-placeholder {
  min-height: 240px;
}

body.mobile-device .reading-overview {
  font-size: 18px;
  line-height: 1.6;
}

body.mobile-device .reading-list h4,
body.mobile-device .feature-result h4 {
  font-size: 17px;
}

body.mobile-device .feature-panel {
  min-height: 0;
}

body.mobile-device .feature-head h3 {
  font-size: 21px;
}

body.mobile-device .chat-log {
  min-height: 300px;
  max-height: 55vh;
}

body.mobile-device .chat-message {
  max-width: 96%;
  font-size: 16px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item,
.empty-history {
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 14px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.history-item strong {
  color: var(--ink);
}

.history-item span,
.empty-history {
  color: var(--muted);
}

.footer {
  color: var(--muted);
  text-align: center;
  font-size: 14px;
  padding-bottom: 8px;
}

.is-loading .read-btn {
  pointer-events: none;
}

.status-error {
  color: var(--danger) !important;
}

.status-success {
  color: var(--success) !important;
}

@media (max-width: 860px) {
  .app-container {
    padding: 18px;
  }

  .header-content,
  .reader-grid,
  .focus-grid,
  .feature-grid {
    grid-template-columns: 1fr;
  }

  .header-content {
    display: grid;
  }

  .time-display {
    justify-content: flex-start;
  }

  .main-title {
    font-size: 36px;
  }

  .brand-mark {
    width: 62px;
    height: 62px;
  }

  .section {
    padding: 18px;
  }

  .model-config {
    align-items: stretch;
    flex-direction: column;
  }

  .reader-grid,
  .focus-grid,
  .feature-grid {
    display: grid;
  }
}

@media (max-width: 520px) {
  .brand-lockup {
    align-items: flex-start;
  }

  .main-title {
    font-size: 31px;
  }

  .tagline {
    font-size: 15px;
  }

  .section-title {
    font-size: 22px;
  }

  .result-header,
  .history-item {
    align-items: flex-start;
    flex-direction: column;
  }

  .ghost-btn {
    width: 100%;
  }

  .source-actions {
    grid-template-columns: 1fr;
  }

  .camera-actions {
    grid-template-columns: 1fr;
  }

  .crop-actions {
    grid-template-columns: 1fr;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }
}
