* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", Calibri, Roboto, Arial, Tahoma, Geneva, Verdana, sans-serif;
}

body {
    padding: 20px;
    color: #333;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    overflow: hidden;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

header {
    padding: 25px;
    text-align: center;
    background: #2c3e50;
    color: white;
}

h1 {
    margin-bottom: 10px;
    font-size: 2.5rem;
}

.home {
    color: unset;
    text-decoration: none;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.8;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    border-bottom: 1px solid #eaeaea;
    padding: 20px;
    background: #f8f9fa;
}

button {
    display: flex;
    align-items: center;
    gap: 8px;
    border: none;
    border-radius: 6px;
    padding: 12px 24px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.print-btn {
    background: #3498db;
    color: white;
}

.print-btn:hover {
    background: #2980b9;
    transform: translateY(-2px);
}

.reset-btn {
    background: #e74c3c;
    color: white;
}

.reset-btn:hover {
    background: #c0392b;
    transform: translateY(-2px);
}

.convert-btn {
    background: #27ae60;
    color: white;
}

.convert-btn:hover {
    background: #219653;
    transform: translateY(-2px);
}

.content {
    padding: 30px;
}

textarea {
    width: 100%;
    height: 200px;
    resize: vertical;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 15px 20px;
    font-size: 16px;
    line-height: 1.6;
}

textarea:focus {
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
    outline: none;
}

textarea::-webkit-scrollbar {
    width: 14px;
}

textarea::-webkit-scrollbar-track {
    border-radius: 0 8px 8px 0;
    background: #fcfcfc;
}

textarea::-webkit-scrollbar-thumb {
    border: 3px solid #fcfcfc;
    border-radius: 8px;
    background: #c1c1c1;
}

textarea::-webkit-scrollbar-track:hover,
textarea::-webkit-scrollbar-thumb:hover {
    cursor: default;
}

textarea::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.output-section {
    min-height: 200px;
    margin: 15px 0 30px 0;
    border-radius: 8px;
    padding: 20px;
    font-size: 20px;
    transition: all 0.3s ease;
}

h2 {
    margin-bottom: 15px;
    border-bottom: 2px solid #3498db;
    padding-bottom: 10px;
    color: #2c3e50;
}

.output-section p {
    margin-bottom: 15px;
    line-height: 1.8;
}

.output-section ul,
.output-section ol {
    margin-bottom: 15px;
    margin-left: 20px;
}

.output-section li {
    margin-bottom: 8px;
}

table {
    width: 100%;
    margin: 20px 0;
    border-collapse: collapse;
    font-size: 16px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

th, td {
    border-bottom: 1px solid #e1e8ed;
    padding: 15px 20px;
    text-align: left;
}

[data-sound]::after {
    content: "";
    display: inline-block;
    width: 18px;
    height: 18px;
    margin-left: 5px;
    vertical-align: bottom;
    background: no-repeat center / contain;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%233498DB' stroke-width='1.5'><polygon points='11 5 6 9 2 9 2 15 6 15 11 19 11 5'/><path d='M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07'/></svg>");
}

[data-sound]:active::after {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%233498DB' stroke-width='1.5'><polygon points='11 5 6 9 2 9 2 15 6 15 11 19 11 5'/><path d='M15.54 8.46a5 5 0 0 1 0 7.07'/></svg>");
}

th {
    font-weight: 600;
    letter-spacing: 0.5px;
    background-color: #3498db;
    color: white;
}

tr:nth-child(even) {
    background-color: #f8f9fa;
}

tr:hover {
    background-color: #e8f4fc;
    transition: background-color 0.3s ease;
}

.hint {
    margin-top: 10px;
    text-align: center;
    font-style: italic;
    color: #7f8c8d;
}

.guide {
    margin: 30px 0;
    white-space: nowrap;
}

.guide table {
    display: block;
    overflow: auto;
    box-shadow: none;
}

footer {
    padding: 20px;
    font-size: 0.9rem;
    text-align: center;
    background: #2c3e50;
    color: white;
}

.userscript {
    color: unset;
    text-underline-offset: 0.125rem;
}

.back-to-top {
    position: fixed;
    bottom: 18px;
    right: 18px;
    z-index: 100;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 50px;
    height: 50px;
    border: 1px solid rgba(3, 11, 26, 0.06);    
    border-radius: 50%;
    padding: 12px;

    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 3px 16px rgba(0, 0, 0, 0.1);

    opacity: 0;
    visibility: hidden;

    cursor: pointer;
    transition: all 0.3s ease;
}

.back-to-top.show {
    opacity: 1;
    visibility: visible;
}

annotated-text {
    position: relative;
    top: 5px;
    line-height: 2.2;
}

ruby.inject-jyutping {
    position: relative;
}

ruby.inject-jyutping > rt {
    position: relative;
    margin-left: 0.1em;
    margin-right: 0.1em;
    font-size: 0.74em;
    font-variant: initial;
    text-transform: initial;
    letter-spacing: initial;
}

ruby.inject-jyutping > rt::before {
    content: var(--onset);
    color: #ad7f58;
}

rhyme::before {
    content: var(--nucleus);
    color: #05a2c2;
}

rhyme::after {
    content: var(--coda);
    color: #889096;
}

ruby.inject-jyutping > rt::after {
    content: var(--tone);
    color: #e54d2e;
}

rhyme {
    vertical-align: baseline !important;
}

.candidates {
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    min-width: 100%;
    background: #fff;
    box-shadow: 0 3px 16px rgba(0, 0, 0, 0.2);
}

.candidates:focus {
    outline: none;
}

.candidates > span {
    min-width: max-content;
    padding-left: 0.2em;
    padding-right: 0.2em;
}

.candidates > span:hover {
    background: rgba(0, 0, 0, 0.1);
}

@media screen and (max-width: 900px) {
    body {
        padding: 0;
    }
    .container {
        border-radius: 0;
    }
}

@media screen and (max-width: 767px) {
    textarea {
        padding: 10px;
    }
    .output-section {
        padding: 0;
    }
    .userscript {
        display: none;
    }
}

@media screen and (max-width: 480px) {
    button {
        gap: 4px;
        padding: 12px;
    }
    .content {
        padding: 20px;
    }
}

@media screen and (max-width: 375px) {
    h1 {
        font-size: 2em;
    }
    button {
        gap: 3px;
    }
}

@media screen and (max-width: 359px) {
    button {
        font-size: 0;
    }
    button::after {
        content: attr(aria-label);
        font-size: 10pt;
    }
}

@media screen and (min-width: 290px) {
    button {
        white-space: nowrap;
    }
}

@media print {
    ruby.inject-jyutping > rt {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    body * {
        visibility: hidden;
    }
    .output-section, .output-section * {
        visibility: visible;
    }
    .output-section {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        margin: 0;
        border-radius: 0;
        padding: 0;
        background: white;
    }
    .hint, .dict, .guide, .reward, .back-to-top {
        display: none;
    }
    @page {
        margin: 1.5cm;
    }
}
