:root {
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: #27332d;
  background: #f5f2ea;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  padding: 16px;
  background: #f5f2ea;
}

.app {
  width: min(900px, 100%);
  margin: 0 auto;
  padding: clamp(20px, 3vw, 30px);
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid #dedbd1;
  border-radius: 22px;
  box-shadow: 0 18px 48px rgba(53, 65, 57, 0.11);
}

h1 {
  margin: 0 0 10px;
  font-size: clamp(30px, 5vw, 48px);
  line-height: 1.15;
}

/* Page title and Home button */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
}

.page-header h1 {
  flex: 1 1 auto;
  min-width: 0;
}

.home-button {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  margin-top: 2px;
  padding: 8px 15px;
  border: 1px solid #50785f;
  border-radius: 999px;
  background: #ffffff;
  color: #50785f;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.home-button:hover,
.home-button:focus-visible {
  background: #50785f;
  color: #ffffff;
}

.home-button:focus-visible {
  outline: 3px solid rgba(80, 120, 95, 0.18);
  outline-offset: 2px;
}

.intro {
  margin: 0 0 16px;
  color: #637068;
  font-size: 17px;
  line-height: 1.65;
}

/* Form stays on one horizontal line */
#emotion-form {
  display: flex;
  flex-flow: row nowrap;
  align-items: stretch;
  gap: 8px;
  width: min(620px, 100%);
}

.emotion-input-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

#emotion-input {
  display: block;
  width: 100%;
  height: 50px;
  min-width: 0;
  margin: 0;
  padding: 10px 14px;
  border: 1px solid #b8c0ba;
  border-radius: 13px;
  background: #fff;
  color: #27332d;
  font: inherit;
  font-size: 18px;
}

#emotion-input:focus {
  outline: 3px solid rgba(80, 120, 95, 0.16);
  border-color: #50785f;
}

.select-button {
  flex: 0 0 auto;
  width: auto;
  height: 50px;
  margin: 0;
  padding: 10px 20px;
  border: 0;
  border-radius: 13px;
  background: #50785f;
  color: #fff;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

/* Hidden on desktop: desktop browser may show its native number spinner */
.mobile-stepper {
  display: none;
}

.error {
  margin: 7px 0 0;
  color: #a33a3a;
}

.error:empty {
  display: none;
}

.result {
  display: grid;
  grid-template-columns: minmax(0, 560px) minmax(150px, 190px);
  align-items: start;
  justify-content: start;
  gap: 18px;
  margin-top: 10px;
}

.preview {
  width: 100%;
  max-width: 560px;
  overflow: hidden;
  border-radius: 14px;
}

.preview img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 560px;
  object-fit: contain;
}

.missing {
  padding: 24px;
  border: 1px solid #ddd8cc;
  border-radius: 14px;
  background: #faf9f5;
  color: #6a716c;
  text-align: center;
  line-height: 1.7;
}

.details {
  min-width: 0;
}

.details h2 {
  margin: 0 0 12px;
  font-size: 20px;
}

.info-row {
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #ece9e1;
}

.label {
  display: block;
  margin-bottom: 2px;
  color: #748078;
  font-size: 12px;
}

.value {
  font-size: 14px;
  overflow-wrap: anywhere;
}

code {
  padding: 2px 6px;
  border-radius: 5px;
  background: #f1efe8;
}

/* Mobile */
@media (max-width: 720px) {
  body {
    padding: 8px;
  }

  .app {
    width: 100%;
    padding: 16px;
    border-radius: 17px;
  }

  h1 {
    font-size: clamp(28px, 8.5vw, 38px);
  }

  .page-header {
    gap: 10px;
  }

  .page-header h1 {
    margin-bottom: 10px;
  }

  .home-button {
    min-height: 34px;
    margin-top: 0;
    padding: 7px 11px;
    font-size: 13px;
  }

  .intro {
    margin-bottom: 13px;
    font-size: 15px;
    line-height: 1.55;
  }

  #emotion-form {
    width: 100%;
    gap: 7px;
  }

  .emotion-input-wrap {
    flex: 1 1 auto;
    min-width: 0;
  }

  /* Hide inconsistent mobile native spinner */
  #emotion-input {
    width: 100%;
    height: 48px;
    min-width: 0;
    padding: 9px 45px 9px 12px;
    font-size: 17px;
    appearance: textfield;
    -moz-appearance: textfield;
  }

  #emotion-input::-webkit-inner-spin-button,
  #emotion-input::-webkit-outer-spin-button {
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
  }

  /* Custom mobile arrows remain inside the input only */
  .mobile-stepper {
    position: absolute;
    z-index: 2;
    top: 2px;
    right: 2px;
    bottom: 2px;
    display: grid;
    grid-template-rows: 1fr 1fr;
    width: 38px;
    overflow: hidden;
    border-left: 1px solid #c4cbc6;
    border-radius: 0 10px 10px 0;
    background: #eef2ef;
  }

  .mobile-stepper button {
    display: grid;
    place-items: center;
    width: 38px;
    min-width: 38px;
    height: auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: #eef2ef;
    color: #405448;
    font: inherit;
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .mobile-stepper button:first-child {
    border-bottom: 1px solid #c4cbc6;
  }

  .mobile-stepper button:active {
    background: #dce5df;
  }

  .select-button {
    flex: 0 0 auto;
    width: auto;
    height: 48px;
    padding: 8px 12px;
    font-size: 15px;
  }

  .result {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    width: 100%;
  }

  .preview,
  .preview img {
    width: 100%;
    max-width: 100%;
  }
}

@media (max-width: 390px) {
  .app {
    padding: 13px;
  }

  .select-button {
    padding-inline: 9px;
    font-size: 14px;
  }

  #emotion-input {
    font-size: 16px;
  }
}

/* ==================================================
   Home button fixed to the top-right corner of the card
   ================================================== */

.app {
  position: relative;
}

.page-header {
  display: block;
  width: 100%;
}

.page-header h1 {
  padding-right: 100px;
}

.home-button {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 10;
  margin: 0;
}

@media (max-width: 720px) {
  .page-header h1 {
    padding-right: 78px;
  }

  .home-button {
    top: 12px;
    right: 12px;
  }
}

/* Privacy notice */
.privacy-note {
  margin: 18px 0 0;
  padding-top: 12px;
  border-top: 1px solid #ece9e1;
  color: #748078;
  font-size: 12px;
  line-height: 1.6;
}
